zoukankan      html  css  js  c++  java
  • IDEA在编辑时提示could not autowire

      

    IDEA在编辑时提示could not autowire

    原创 2016年05月14日 10:53:38

    在开发中我再applicationContext-dao.xml中加入了mapper扫描器

    [html] view plain copy
     
    1. <!--mapper扫描器-->  
    2. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
    3.     <!--扫描包路径,如果需要扫描多个包,中间使用半角逗号隔开-->  
    4.     <property name="basePackage" value="com.qianlv.ssmdemo.mapper" />  
    5.     <!--这里不用sqlSessionFactory是因为如果用会导致上面配置的dataSource失效-->  
    6.     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />  
    7. </bean>  

    但是在编辑一个Service中注入mapper会提示could not autowire,但是可以正常执行的。
    [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. }  
    我们需要改一下IDEA的设置

    IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示

    转载 2017年02月07日 10:20:42

    1.问题描述

      在Idea的spring工程里,经常会遇到Could not autowire. No beans of 'xxxx' type found的错误提示。但程序的编译和运行都是没有问题的,这个错误提示并不会产生影响。但红色的错误提示在有些有强迫症的程序员眼里,多多少少有些不太舒服。

    2. 原因

            原因可能有两个,第一个是IntellijIDEA本身工具的问题。第二个便是我们导入@Service包的时候导入包错误造成的

      第一种原因,spring auto scan配置,在编辑情况下,无法找不到对应的bean,于是提示找不到对应bean的错误。常见于mybatis的mapper,如下:

    <!-- 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. 解决方案

      针对第一种原因,解决办法是:降低Autowired检测的级别,将Severity的级别由之前的error改成warning或其它可以忽略的级别。

           针对第二种原因,解决方案当然是导入正确的包。首先我们来看下最容易导入的错误包,如下所示:

    import com.alibaba.dubbo.config.annotation.Service;
       正确的包应该是下面这个
    
    
    import org.springframework.stereotype.Service;

     

  • 相关阅读:
    public,protected,private辨析
    转载---Java集合对象的深度复制与普通复制
    SSM框架学习之高并发秒杀业务--笔记4-- web层
    PCB布线总的原则
    模拟电子技术目录
    放大器(PA+LAN)在射频上的应用
    AD软件Bug和自我失误的对战
    二、cadence焊盘与封装制作操作步骤详细说明
    图腾柱电路工作原理
    转载:介绍AD另外一种奇葩的多通道复用的方法
  • 原文地址:https://www.cnblogs.com/pejsidney/p/8856977.html
Copyright © 2011-2022 走看看