在springmvc中注入服务时用@Service

当有两个实现类时都标明@Service后则会出现异常:

nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.james.dao.impl.BaseDao] is defined: expected single matching bean but found 2:

这是因为都标明了@Service会自动注入,这时会导致不清楚实际运行时实例化哪一类。

解决:

方法一

实际运用哪一个实现类就在哪个类上注入@Service,另外一个不标注

方法二

都不标注@Service,在resource文件夹中配置 applicationContext.xml,表明实际运行哪个实现类。

  1. <bean id="serviceImpl" class="com.james.service.impl.ServiceImpl"></bean>

springmvc注入类 NoUniqueBeanDefinitionException: No qualifying bean of type [] is defined: expected single错误的更多相关文章

  1. 多个@bean无法通过@resource注入对应的bean(org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found )

    一.异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ' ...

  2. Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]

    环境为Spring + Spring mvc + mybatis:其中Spring版本为4.1.4 spring配置文件: <?xml version="1.0" encod ...

  3. 【Spring】手动获取spring容器对象时,报no qualifying bean of type is defined

    手动获取容器对象时,报no qualifying bean of type is defined, 经过调查,发现手动获取的时候,该类所在的包必须经过spring容器初始化. 1.SpringConf ...

  4. [zhuanzai]Bean对象注入失败 .NoSuchBeanDefinitionException: No qualifying bean of type..

    nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying b ...

  5. 关于SpringMVC未找到类[No qualifying bean of type [...]is defined]问题

    首先,不要慌,出现这个问题肯定是某一个配置注解没写上.. 无非就几个地方: 1.控制层是否添加@Controller or 需要pring管理的类是否添加@Component 2.DAO层是否添加@R ...

  6. Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined

    1. Overview In this article, we are discussing the Springorg.springframework.beans.factory.NoSuchBea ...

  7. spring注入时报错::No qualifying bean of type 'xxx.xxMapper'

    做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Auto ...

  8. 使用springmvc的时候报错NoSuchBeanDefinitionException: No qualifying bean of type

    NoSuchBeanDefinitionException: No qualifying bean of type 其实我至今都不知道错误的根源在哪里,<context:component-sc ...

  9. NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

    报错如下: NoSuchBeanDefinitionException:No qualifying bean of type   found for dependency: expected at l ...

随机推荐

  1. OBS源码解析(2)run_program函数

    static int run_program(fstream &logFile, int argc, char *argv[]){ /*初始化和读取profile相关信息*/ int ret ...

  2. 关于sqlmap使用手册

    sqlmap 使用手册 官方wiki Github sqlmap也是渗透中常用的一个注入工具,可以用来检测sql注入漏洞. 功能与作用 完全支持MySQL,Oracle,PostgreSQL,Micr ...

  3. 【剑指Offer学习】【面试题21:包括min 函数的栈】

    题目: 定义栈的数据结构,请在该类型中实现一个可以得到栈的最小素的min 函数.在该栈中.调用min.push 及pop的时间复杂度都是0(1) 解题思路: 把每次的最小元素(之前的最小元素和新压入战 ...

  4. 局域网使用的IP地址范围

    局域网可用的IP地址范围为: A类地址:10.0.0.0 - 10.255.255.255  B类地址:172.16.0.0 - 172.31.255.255 C类地址:192.168.0.0 -19 ...

  5. Android 四大组件学习之ContentProvider四

    上节我们学习了怎样去读取系统短信以及插入一条短信到系统中. 本节我们学习怎样获取系统的联系人,以及插入一条联系人 好.废话不多说了,直接操作. 首先和读取短信一样,先找到联系人在数据库中的位置. wa ...

  6. 游戏服务端中使用Servlet和Java注解的一个好设计

    SNS类游戏基本都是使用HTTP短连接,用Java来开发服务端时能够使用Servlet+Tomcat非常轻松的架构起服务端来.在这里介绍一种使用Servlet比較好的一种设计,我也见过非常多基于HTT ...

  7. Clang-Format: Visual Studio Style

    PointerAlignment: Left UseTab: Never IndentWidth: 4 BreakBeforeBraces: Allman AllowShortIfStatements ...

  8. utf8、unicode与gbk

    中国人民通过对 ASCII 编码(对于英文字母8位)的中文扩充改造,产生了 GB2312 编码,可以表示6000多个常用汉字. 汉字实在是太多了,包括繁体和各种字符,于是产生了 GBK (汉字:两个字 ...

  9. 浏览器兼容性--IE11以及Edge等下载文件的中文名出现乱码,前后端解决方案

    项目中有用到文件下载功能,之前在处理下载时对IE浏览器下文件下载名进行过处理,测试也没有问题,但是功能上线后,业务反馈IE11文件下载文件名依然乱码.打印User-Agent字符串如下: IE11 U ...

  10. iOS设计模式之懒加载

    一.为什么要懒加载? 答: iPhone设备内存有限,如果在程序在启动后就一次性加载将来会用到的所有资源,那么久可能会耗尽iOS设备的内存.这些资源例如大量的数据,图片,音频,过多的控件等. 二.懒加 ...