版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_38004638/article/details/97923811
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-07-31 15:33:15.798 ERROR 14420 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
*************************** APPLICATION FAILED TO START ***************************
Description:
Field idWorker in com.example.springbootmybatis.controller.TeacherController required a bean of type 'com.aspire.commons.autoid.IdWorker' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.aspire.commons.autoid.IdWorker' in your configuration.
同时注入报红
1、Idea设置为警告,或者降低检测级别@Autowired(required = false)
2、更改@Autowired为@Resource
3、在服务层加上注解@Service或
在mapper接口类上加上@Repository或@Component标签
确保包导入正确,@Service正确导入的是import org.springframework.stereotype.Service;
4、启动类放在所有类外层,保证能扫描到所有子包。或者在启动类上添加扫描路径
@ComponentScan(basePackages = {"com.xxx"})
@ComponentScan(basePackageClasses= XXXController.class)
@SpringBootApplication(scanBasePackages={"com.xxx"})
5、在启动类中配置@Bean,或者在引用类上添加@Bean注解
在一个配置类中定义这个类,即可正确修复。 @Bean public IdWorker idWorker() { return new IdWorker(); }
6、mapper接口提示:Could not autowire. No beans of 'XXXMapper' type found.
使用到mapper的类序列化,即实现Serializable 接口即可
每个Mapper类中添加 @Mapper
在application.java启动类前面加上 @MapperScan(),参数为dao层包的路径