idea取消could not autowire. no beans of 'xxxx' type found的錯誤提示

在Idea的spring工程裏,經常會遇到Could not autowire. No beans of 'xxxx' type found的錯誤提示。但程序的編譯和運行都是沒有問題的,這個錯誤提示並不會產生影響。但紅色的錯誤提示在有些有強迫症的程序員眼裏,多多少少有些不太舒服。

 

原因:

spring auto scan配置,在編輯情況下,無法找不到對應的bean,於是提示找不到對應bean的錯誤。常見於mybatis的mapper,如下:


 
  1. <!-- mapper scanner configurer -->

  2. <bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">

  3. <property name="basePackage" value="com.kq.mapper" />

  4. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

  5. </bean>

 

解決方法:

降低Autowired檢測的級別,將Severity的級別由之前的error改成warning或其它可以忽略的級別

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章