在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,表明实际运行哪个实现类。

<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. Maven项目pom.xml文件报xxx\target\classes\META-INF\MANIFEST.MF (系统找不到指定的路径)

    在今天的学习Maven项目中遇到的这个错误:pom.xml文件报xxx\target\classes\META-INF\MANIFEST.MF (系统找不到指定的路径) 在Maven项目学习中,缓存问 ...

  2. 【NOIP2014提高组】寻找道路

    https://www.luogu.org/problem/show?pid=2296 满足条件的路径:路径上的所有点的出边所指向的点都与终点连通.反过来,不满足条件的路径:路径上至少一点的出边所指向 ...

  3. Java实现字符串转换十六进制MD5值

    public class Encode {    public final static String md5(String s) {        char hexDigits[] = { '0', ...

  4. 用shell制作IP脚本

    vim  ip.sh #!/bin/bashread -p "eth:" eread -p "ip:" ip1read -p "netmask:&qu ...

  5. 谷哥的小弟学前端(11)——JavaScript基础知识(2)

    探索Android软键盘的疑难杂症 深入探讨Android异步精髓Handler 具体解释Android主流框架不可或缺的基石 站在源代码的肩膀上全解Scroller工作机制 Android多分辨率适 ...

  6. CentOS安装java and javac(java执行环境和开发环境)

    [root@localhost usr]# yum install java Loaded plugins: fastestmirror, refresh-packagekit, security R ...

  7. vim配置分享(持续更新中)

    作者:zhanhailiang 日期:2014-10-24 set nocompatible set nu   "" 自己主动缩进 syntax on set autoindent ...

  8. Android 防内存泄露handler

    Android 防内存泄露handler 1.使用弱引用 WeakRefHander /** * 作者: allen on 15/11/24.感谢开源作者https://coding.net/u/co ...

  9. java文本编辑器v2.0 图形用户界面

    package 文本编辑器; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; impor ...

  10. 自学Python3.3-字符串格式化 作用域 递归

    一.字符串格式化 二.作用域 三.递归