Java Autowired annotation error problem solving

When using springboot to integrate mybatis, using automatic injection to inject a mapper in the controller, a Could not autowire. No beans of'xxxx' type found error occurred, indicating that the bean cannot be automatically injected. In fact, if the problem does not report an error when the program is compiled and run, it may just be a problem with IntelliJ idea. If it cannot be compiled and run normally, it may be spring auto scan configuration. Under editing, the corresponding bean cannot be found, so Prompt that the corresponding bean cannot be found error.

**1. The solution for the normal compilation and operation but the error message still appears: ** Reduce the level of Autowired detection, and change the level of Severity from the previous error to warning or other levels that can be ignored.
Insert picture description here
2. The solution for not being able to compile and run normally : import the package correctly, if it is to check whether the package of the class in the error message is imported correctly, this kind of error is most common under the mapper in mybatis, such as the comment on mybatis Version or configuration file version of the solution:

①.配置文件版:在全局配置文件中,配置要自动扫描进容器的包
<!-- mapper scanner configurer -->
<bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.wp.spring.mybatis.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
②.注解版:在运行的主类上加上注解:@MapperScan(value = "要自动扫描的包")-->(springboot整合mybatis的时候)。或则在mybatis项目中的mapper类上面加上注解@Mapper标识这是一个mapper,容器启动的时候就会自动加入到容器中了。示例如下:

1.springboot主类:

Insert picture description here

2. Mybatis mapper class:
Insert picture description here

Guess you like

Origin blog.csdn.net/CharlesYooSky/article/details/108244976