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

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层包的路径

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页