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. webbench-1.5_hacking

    /**************************************************************************** * * webbench-1.5_hacki ...

  2. 【其他】msb-lsb-intel-motorola大小端问题

    MSB(Most Significant Bit) 最高有效位: LSB(Least Significant Bit) 最低有效位 intel格式:低字节在前 Motorola格式:高字节在前 参考1 ...

  3. Ubuntu中敲写c语言步骤

    1.进入Ubuntu界面 1.1按快捷键 Ctrl + Alt + T: 1.2 安装vim:输入 sudo apt-get install vim: 1.3 安装gcc:输入 sudo apt-ge ...

  4. PNG文件结构

    对于一个PNG文件来说,其文件头总是由位固定的字节来描述的,HEX: 89 50 4E 47 0D 0A 1A 0A 使用ultra打开一个png图片,结果如下: 其中第一个字节0x89超出了ASCI ...

  5. python 二维list取列

    b = [i[0] for i in a] # 从a中的每一行取第一个元素.

  6. Dataframe 中的 and vs &

    refer to: http://dougaoyang.github.io/2017/09/22/pandas-bool-compare.html df[(df['pop']>3) and (d ...

  7. nuclio dokcer 运行测试

    nuclio serverless 平台,可以方便的进行实时事件以及数据处理应用的开发 dcoker 运行 启动 docker run -d -p 8070:8070 -v /var/run/dock ...

  8. 转oracle 学习- 数据类型

    oracle数据类型 有道是,磨刀不误砍柴工.多了解一些底层的东西,对于Oracle开发.维护大有裨益.个人总结了一些Oracle数据类型集解,相信读者阅读了本文以后,Oracle数据库开发起来会事半 ...

  9. hadoop 知识点

    HDFS 命令 命令 说明 fsck 检查文件的完整性 start-balancer.sh 重新平衡HDFS hdfs dfs -copyFromLocal 从本地磁盘复制文件到HDFS hadoop ...

  10. admin.ModelAdmin 后台管理关联对象,某个字段怎么显示值

    admin.ModelAdmin 后台管理关联对象,某个字段如何显示值?对象 WxpAccount:              accountName = ... 对象 AccountMenu:    ...