2016-12-22 9 views
1

私はSpringBoot 1.4.0.RELEASEを使用しています。ここに私のプロジェクト構造ツリーはここでは、このRepo Beanをオートワイヤできない

com 
└── projectname 
    ├── Application.java 
    ├── api 
    │   ├── authentication 
    │   │   ├── AuthenticatedUser.java 
    │   │   ├── AuthenticationRequest.java 
    │   │   ├── AuthenticationToken.java 
    │   │   ├── AuthenticationTokenFilter.java 
    │   │   ├── AuthenticationTokenUtil.java 
    │   │   ├── JwtAuthenticationEntryPoint.java 
    │   │   └── PasswordRequest.java 
    │   ├── common 
    │   │   └── CommonClasses.java 
    │   ├── config 
    │   │   ├── DbConfiguration.java 
    │   │   ├── SimpleCORSFilter.java 
    │   │   └── WebSecurityConfig.java 
    │   └── service 
    │      └── AuthenticationService.java 
    └── persistence 
     ├── domain 
     │   └── User.java 
     ├── repository 
     │   └── UserRepo.java 
     └── service 
      └── UserService.java 

のように見える私はSpring

のための私のApplication.javaクラスを設定しているかApplication.java

@SpringBootApplication 
@ComponentScan 
@EnableAutoConfiguration 
@EnableSwagger2 
@Log 
public class Application extends SpringBootServletInitializer { 
    private static Class<Application> app = Application.class; 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(app, args); 
    } 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(app); 
    } 
    //other methods to configure swagger and security 
} 

UserRepo

どのように見えるかです
public interface UserRepo extends MongoRepository<User, String> { 
    User findById(String emailId); 

    List<User> findAll(); 

} 

とは、私は、アプリケーションがuserRepo Beanを見つけることができなかったという例外をスローしてログインのauthenticationServiceuserServiceを使用しようとしていますときに私は、今

@Service 
public class UserService { 
    @Autowired 
    private UserRepo userRepo; 
    // methods to fetch data 
    } 

UserService.javaを実装しているかのthats。私がここで行方不明です何、ここではこのような何か、あなたはおそらく春データのMongoDBの設定を追加するのを忘れたり、間違ったbasePackagesを使用して例外

14:31:32,930 ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 9) Application startup failed: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService': Error creating bean with name 'authenticationService': Unsatisfied dependency expressed through field 'userService': Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepo': No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepo': No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authenticationService': Unsatisfied dependency expressed through field 'userService': Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepo': No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepo': No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.projectname.persistence.repository.UserRepo] found for dependency [com.projectname.persistence.repository.UserRepo]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) 
    at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:150) 
    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:130) 
    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86) 
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) 
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:184) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
    at org.jboss.threads.JBossThread.run(JBossThread.java:320) 
+0

あなたUserRepoはインタフェースであり、それを変更しますクラス。 – Kalenda

+0

スプリングデータにはどうなっているのでしょうかhttp://docs.spring.io/spring-data/mongodb/docs/1.2.0.RELEASE/reference/html/mongo.repositories.html –

+0

これは正しいです。もう1つは、プライベートキーワードです。 '@Autowired UserRepo repository;' – Kalenda

答えて

3

です:

@Configuration 
@EnableMongoRepositories(basePackages = "com.projectname.persistence") 
class ApplicationConfig extends AbstractMongoConfiguration { 
//... 
} 
+0

私によく見えます!また、OP @ Emに戻って、ここで春のガイドを見てみましょう:https://spring.io/guides/gs/accessing-data-mongodb/ – ndrone

+0

ありがとう。それは私の問題を解決した。また、他の人にとっては、永続性が別のJARファイルであっても実際にはうまくいきます –

関連する問題