IDEA prompts could not autowire when editing
During development I added mapper scanner to applicationContext-dao.xml
- <!--mapper-scanner-->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <!--Scan package path, if you need to scan multiple packages, separate them with commas-->
- <property name="basePackage" value="com.qianlv.ssmdemo.mapper" />
- <!--The sqlSessionFactory is not used here because if it is used, the dataSource configured above will fail-->
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
- </bean>
But injecting mapper in editing a Service will prompt could not autowire, but it can be executed normally.
- public class ItemsServiceImpl implements com.qianlv.ssmdemo.service.ItemsService{
- @Autowired
- ItemsMapperCustom itemsMapperCustom;
- public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception {
- return itemsMapperCustom.findItemsList(itemsQueryVo);
- }
- }
IntelliJ Idea solves the error message of Could not autowire. No beans of 'xxxx' type found
1. Problem description
In Idea's spring project, the error message "Could not autowire. No beans of 'xxxx' type found" is often encountered. But there is no problem with the compilation and operation of the program, and this error message will not affect it. But the red error prompt is somewhat uncomfortable in the eyes of some programmers with obsessive-compulsive disorder.
2. Reason
The first reason is that the spring auto scan configuration cannot find the corresponding bean in the case of editing, so it prompts an error that the corresponding bean cannot be found. Commonly used in mybatis mapper, as follows:
<!-- mapper scanner configurer --> <bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.adu.spring_test.mybatis.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean>
3. Solutions
For the first reason, the solution is to 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.
For the second reason, the solution is of course to import the correct package. First let's take a look at the error package that is easiest to import, as follows:
import com.alibaba.dubbo.config.annotation.Service;
The correct package should be the following
import org.springframework.stereotype.Service;
1. Problem description
In Idea's spring project, the error message "Could not autowire. No beans of 'xxxx' type found" is often encountered. But there is no problem with the compilation and operation of the program, and this error message will not affect it. But the red error prompt is somewhat uncomfortable in the eyes of some programmers with obsessive-compulsive disorder.
2. Reason
The first reason is that the spring auto scan configuration cannot find the corresponding bean in the case of editing, so it prompts an error that the corresponding bean cannot be found. Commonly used in mybatis mapper, as follows:
<!-- mapper scanner configurer --> <bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.adu.spring_test.mybatis.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean>
3. Solutions
For the first reason, the solution is to 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.
For the second reason, the solution is of course to import the correct package. First let's take a look at the error package that is easiest to import, as follows:
import com.alibaba.dubbo.config.annotation.Service;
The correct package should be the following
import org.springframework.stereotype.Service;