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. Eclipse之NDK编译-- Type 'jint' could not be resolved, and JNIEnv, jclass错误解决办法

    最近在研究面部识别美白相关的功能.使用的是opencv,就去研究了.今天正好有空就把安装了ndk,安装完成之后就试图去编译demo程序,hellow-jni c代码,一开始编辑就报错了3个错误信息: ...

  2. exit和return

    函数名: exit() 所在头文件:stdlib.h(如果是”VC6.0“的话头文件为:windows.h) 功 能: 关闭所有文件,终止正在执行的进程. exit(1)表示异常退出.这个1是返回给操 ...

  3. bug20170125

    1s定时请求接口,接口不响应(接口挂掉),浏览器崩溃

  4. 《DSP using MATLAB》Problem 3.5

    定义为: 如果序列绝对可和,其DTFT就存在.

  5. dbt 基本试用

    dbt 是一个很不错的进行etl 中的t 处理的工具,灵活简单,我们需要写的就是select 语句 dbt 帮助我们进行处理 测试集成了graphql 以及使用docker 运行 安装 pip ins ...

  6. Where is Silverlight now?

    Some time ago, I wrote an article about the comparison between HTML5 and Silverlight. That article w ...

  7. POJ1325机器重启次数——二分图匈牙利算法模板

    题目:http://poj.org/problem?id=1325 求最小点覆盖.输出最大匹配数就行,结果略复杂地弄了. 注意由题可知 可以直接把与0有关的边删掉.不过亲测不删0而计数时不计0就会WA ...

  8. Oracle RAC的机制与测试方法

    Oracle RAC的机制与测试方法 标签: rac 机制 测试 2016-05-25 09:54 1150人阅读 评论(0) 收藏 举报  分类: oracle(2)  1.RAC原理 Oracle ...

  9. [转]oracle导入提示“IMP-00010:不是有效的导出文件,头部验证失败”的解决方案

    这是由于导出的dmp文件与导入的数据库的版本不同造成的用Notepad++查看了dmp文件,在头部具修改成你将导入目标数据库的版本号以下对应的版本号: 11g R2:V11.02.00 11g R1: ...

  10. <<APUE>> 编译方法

    /********************************************************************************第0种-最简单实用********** ...