Ich verwende SpringBoot 1.4.0.RELEASE
. Mein Projekt Strukturbaum sieht wie folgt ausRepo-Bean kann nicht automatisch ausgelöst werden
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
Hier ist, wie ich konfiguriert habe meine Application.java
Klasse für Spring
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
}
Hier ist, wie UserRepo sieht aus wie
public interface UserRepo extends MongoRepository<User, String> {
User findById(String emailId);
List<User> findAll();
}
und das ist, wie ich meine UserService.java
@Service
public class UserService {
@Autowired
private UserRepo userRepo;
// methods to fetch data
}
nun umgesetzt haben, wenn ich versuche, userService
in authenticationService
für die Anmeldung zu verwenden, wird Anwendungsausnahme zu werfen, dass es nicht userRepo
Bohne finden konnten. Was ich hier fehlt, ist hier die Ausnahme
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)
Ihre UserRepo ist eine Schnittstelle, ändern Sie ihn auf eine Klasse. – Kalenda
So soll es im Frühjahr sein http://docs.spring.io/spring-data/mongodb/docs/1.2.0.RELEASE/reference/html/mongo.repositories.html –
Das stimmt. Die andere Sache, die mir in den Sinn kommt, ist das private Schlüsselwort. '@Autowired UserRepo-Repository;' – Kalenda