一、问题描述

     运行 SpringBoot 的启动类时报错,错误详情:


APPLICATION FAILED TO START


Description:

Field idWorker in com.changgou.goods.service.impl.SpuServiceImpl required a bean of type ‘entity.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 ‘entity.IdWorker’ in your configuration.
    
这里的 entity.IdWorker 是 我自己工程里的实体类包 entity 中的一个类,它说识别不到这个 bean (如果遇到 import 自己工程里的实体类包爆红的话,可以试试 IDEA 的 Invailidate Caches/Restart 清除缓存并重启)。
    

二、解决方法

     在 启动类上添加注解,手动把这个实体类注册到容器中:

@Configuration
@Import({entity.IdWorker.class})
public class GoodsApplication {

     再去运行启动类就没问题了。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐