spring boot开发 @autowired注入失败

时间:2021-10-05 21:46:19

@autowired注入失败 会出现如下错误提示:

2018-05-28 08:39:41.857  INFO 8080 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.17.Final}
2018-05-28 08:39:41.859 INFO 8080 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-05-28 08:39:41.988 INFO 8080 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-05-28 08:39:42.143 INFO 8080 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-05-28 08:39:42.288 INFO 8080 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-05-28 08:39:42.561 WARN 8080 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'BController': Unsatisfied dependency expressed through field 'supplierService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.nenu.service.SupplierService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-05-28 08:39:42.561 INFO 8080 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-05-28 08:39:42.562 INFO 8080 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-05-28 08:39:42.566 INFO 8080 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2018-05-28 08:39:42.568 INFO 8080 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-05-28 08:39:42.580 INFO 8080 --- [ restartedMain] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-28 08:39:42.718 ERROR 8080 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Field supplierService in com.nenu.controller.BController required a bean of type 'com.nenu.service.SupplierService' that could not be found. Action: Consider defining a bean of type 'com.nenu.service.SupplierService' in your configuration.

修改:

SupplierServiceImpl 没有添加@service注入

spring boot开发 @autowired注入失败

参考链接:https://blog.csdn.net/chengdu456/article/details/39504057