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.

 

同时注入报红

Could not autowire. No beans of 'xxx' type found_第1张图片

1、Idea设置为警告,或者降低检测级别@Autowired(required = false)

2、更改@Autowired为@Resource

Could not autowire. No beans of 'xxx' type found_第2张图片

3、在服务层加上注解@Service或

在mapper接口类上加上@Repository或@Component标签

确保包导入正确,@Service正确导入的是import org.springframework.stereotype.Service;

Could not autowire. No beans of 'xxx' type found_第3张图片

4、启动类放在所有类外层,保证能扫描到所有子包。或者在启动类上添加扫描路径

@ComponentScan(basePackages = {"com.xxx"})

@ComponentScan(basePackageClasses= XXXController.class)

@SpringBootApplication(scanBasePackages={"com.xxx"})

5、在启动类中配置@Bean,或者在引用类上添加@Bean注解

在一个配置类中定义这个类,即可正确修复。
 @Bean
    public IdWorker idWorker() {
        return new IdWorker();
    }

Could not autowire. No beans of 'xxx' type found_第4张图片

 

6、mapper接口提示:Could not autowire. No beans of 'XXXMapper' type found.

使用到mapper的类序列化,即实现Serializable 接口即可

Could not autowire. No beans of 'xxx' type found_第5张图片

每个Mapper类中添加 @Mapper

在application.java启动类前面加上 @MapperScan(),参数为dao层包的路径

你可能感兴趣的:(bug)