IDEA在编辑时提示could not autowire

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

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

  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,但是可以正常执行的。

  1. public class ItemsServiceImpl implements com.qianlv.ssmdemo.service.ItemsService{
  2. @Autowired
  3. ItemsMapperCustom itemsMapperCustom;
  4. public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception {
  5. return itemsMapperCustom.findItemsList(itemsQueryVo);
  6. }
  7. }

我们需要改一下IDEA的设置

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

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

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;

IDEA在编辑时提示could not autowire的更多相关文章

  1. dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法

    dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法 dedecms出现这个问题与代码无关,主要是和PHP的版本有关,用的PHP5.4,更换成PHP5.2之后就不会有这个问题了. 问题 ...

  2. Idea添加Jetty时提示JMX module is not included

    添加自己的jetty时提示下图 此时,我们应该编辑jetty根目录下 start.ini 添加 "--module=jmx" 此时就可以成功添加了 原因:因为在9.07的时候默认情 ...

  3. eclipse打开时提示:failed to create the java virtual machine

    Eclipse打开时提示: failed to create the java virtual machine 原因:C盘空间不够   编辑删除 处理:1.用金山清理临时文件: 2.用金山手机卫士连接 ...

  4. 关于pip安装时提示"pkg_resources.DistributionNotFound"错误

    使用pip install --upgrade pip升级pip中途失败,再次安装pip,完成后出现如下错误: 尝试重新安装pip也不行,同样会出现上述问题. 此时我们查看/usr/bin/pip文件 ...

  5. Ubuntu开机时提示“piix4_smbus 0000:00:07.3: SMBus Host controller not enabled”

    问题描述:Ubuntu开机时提示“piix4_smbus 0000:00:07.3: SMBus Host controller not enabled” 版本:Ubuntu 18.04    VMw ...

  6. 安装Centos7时提示 /dev/root does not exits

    安装centos 7时提示 "Warning: /dev/root does not exist, could not boot" 这个问题是木有找到你的U盘. 在一个能够编辑U盘 ...

  7. 执行shell脚本时提示bad interpreter:No such file or directory的解决办法

    执行shell脚本时提示bad interpreter:No such file or directory的解决办法 故障现象:在终端直接cd /var正常,在shell脚本中执行则报错.原因是脚本是 ...

  8. Linux:redhat6.5使用yum时提示需要注册问题解决方案

    Linux:redhat6.5使用yum时提示需要注册问题解决方案 一.问题 新安装了redhat6.5.安装后,登录系统,使用yum时候.提示: This system is not registe ...

  9. Netbeans打开包括中文文件时提示错误

    Netbeans打开包括中文文件时提示错误.在Netbeans里找了半天没找到怎么设置,最后发现要改动Netbeans的配置文件才干解决. 编辑C:\Program Files\NetBeans 8. ...

随机推荐

  1. Magento邮件发送完美设置

    Magento新站上线伊始,不料在邮件上遇到了问题.此时常用的邮件模板已经编辑完毕,诸如New Account, New Order, Password Forget等. CentOS下发送邮件很简单 ...

  2. ORA-10922 Temporary tablespace group is empty错误

    错误--练习查询,发现报错: SQL>  select * from range_list_part_tab where id=100000Execution Plan------------- ...

  3. Ubuntu install TensorFlow

    /******************************************************************************** * Ubuntu install T ...

  4. BZOJ4475: [Jsoi2015]子集选取【找规律】【数学】

    Description Input 输入包含一行两个整数N和K,1<=N,K<=10^9 Output 一行一个整数,表示不同方案数目模1,000,000,007的值. Sample In ...

  5. ElasticSearch(三):ES单机版本基本操作之删除,修改,插入

    1. 创建索引 1.1 直接创建索引 可以直接使用head插件创建索引,指定分片数和备份数即可.如下图: 1.2 创建结构化索引 上图创建的索引,点开索引信息,mapping是空的,表示该索引的字段并 ...

  6. 《DSP using MATLAB》Problem 4.17

  7. CSS 属性用法备忘录

    ☆ margin: 0; padding: 0; :{ 顺时针 margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: ...

  8. 调用飞信HTTP接口给自己发短信

    注: 1.下文中所有HTTP请求所指的Host都是f.10086.cn 2.目前只有中国移动用户可以使用 1.打开登录页面:GET /huc/user/space/login.do?m=submit& ...

  9. tomcat源码阅读之过滤器

    一.Servlet过滤器: 1.介绍: Servlet过滤器本身并不生成请求和响应对象,它只提供过滤作用. Servlet过滤器能够在Servlet被调用之前检查Request对象,修改Request ...

  10. centos6 ext4修复

    输入root密码后: fsck -y /dev/mapper/vg_logserv-lv_root 修复完后重启 reboot 若忘记了root密码,可用系统ISO盘引导进入Rescue救援模式 在这 ...