spring boot啟動報錯 NoSuchBeanDefinitionException


在啟動springboot時,autowired自動注入報錯,

 

2017-05-26 15:23:05.761  WARN 46372 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTest': Unsatisfied dependency expressed through field 'mongoDaoTest'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'mongo.MongoDaoTest' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2017-05-26 15:23:05.764  INFO 46372 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2017-05-26 15:23:05.789  INFO 46372 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-26 15:23:05.891 ERROR 46372 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field mongoDaoTest in mongo.MongoTest required a bean of type 'mongo.MongoDaoTest' that could not be found.


Action:

Consider defining a bean of type 'mongo.MongoDaoTest' in your configuration.

 

會提示注入失敗,可以嘗試把@EnableAutoConfiguration注解換成@SpringBootApplication;

@SpringBootApplication 注解效果等同於 @Configuration,@EnableAutoConfiguration 及 @ComponentScan 這三個注解一起使用,所以不要在 Controller 上面添加 @EnableAutoConfiguration 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM