前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Could not autowire. No beans of 'xxx' type found

Could not autowire. No beans of 'xxx' type found

作者头像
chenchenchen
发布2019-09-02 17:44:17
4.4K0
发布2019-09-02 17:44:17
举报
文章被收录于专栏:chenchenchenchenchenchen

版权声明:本文为博主原创文章,遵循 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层包的路径

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年07月31日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档