IDEA prompts could not autowire when editing

  

IDEA prompts could not autowire when editing

Original  May 14, 2016 10:53:38

During development I added mapper scanner to applicationContext-dao.xml

 

[html]  view plain copy  
 
  1. <!--mapper-scanner-->  
  2. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  3.     <!--Scan package path, if you need to scan multiple packages, separate them with commas-->  
  4.     <property name="basePackage" value="com.qianlv.ssmdemo.mapper" />  
  5.     <!--The sqlSessionFactory is not used here because if it is used, the dataSource configured above will fail-->  
  6.     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />  
  7. </bean>  

But injecting mapper in editing a Service will prompt could not autowire, but it can be executed normally.

 

[java]  view plain copy  
 
  1. public class ItemsServiceImpl implements com.qianlv.ssmdemo.service.ItemsService{  
  2.   
  3.     @Autowired  
  4.     ItemsMapperCustom itemsMapperCustom;  
  5.   
  6.     public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception {  
  7.         return itemsMapperCustom.findItemsList(itemsQueryVo);  
  8.     }  
  9.   
  10. }  
We need to change the settings of IDEA

IntelliJ Idea solves the error message of Could not autowire. No beans of 'xxxx' type found

Reprinted  on February 7, 2017 at 10:20:42

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

        There may be two reasons, the first is a problem with IntellijIDEA's own tools. The second is caused by the import package error when we import the @Service package

  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

        There may be two reasons, the first is a problem with IntellijIDEA's own tools. The second is caused by the import package error when we import the @Service package

  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;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324500755&siteId=291194637