在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. Foxmail 7.0破解版,拷贝到新机器后,发送邮件乱码问题

    申请了新机器,挺开心,键盘和鼠标也好用了,但是新机器也随之而来一些不便,以前存储的数据需要重新拷贝.还有一些邮件,有些邮件标记了*号. Foxmail7.0绿色版本还挺好用,直接拷贝到新机器上就能直接 ...

  2. 【luogu P1186】玛丽卡

    https://www.luogu.org/problem/show?pid=1186 考虑暴力,枚举图上每一条边删去后跑Dijkstra,取M次的最大值. 仔细想想就会发现删除最短路以外的边对最短路 ...

  3. Web Service vs WCF vs WCF REST vs Web API

    [MY NOTE] Translate Source:http://www.dotnettricks.com/learn/webapi/difference-between-wcf-and-web-a ...

  4. 自学Python全栈开发的第二次笔记(Python需要注意的地方)

    好几天没写blog了,今天整理整理.写blog一定要坚持下去.     Python解释器 #!/usr/bin/env python #-*-coding:utf-8-*-   #  无效的内容,只 ...

  5. pl/sql中if的用法

    /*判断用户从键盘输入的数字1.如何使用if语句2.接收一个键盘输入(字符串)*/set serveroutput on--接收一个键盘输入--num:一个地址值:含义:在该地址上保存了输入的值acc ...

  6. Apache OFBiz源码解读之MVC模型

    节点解析 request-map 你可以将其理解为controller的配置,如果你了解或使用过struts的配置或springmvc的annotation,就会发现这个定义跟它们是很相似的: [ht ...

  7. python入门基础

    Python 入门 变量 什么是变量?变量就是变化的量,核心是"变"和"量"两个字,变就是变化,量就是衡量状态. 为什么需要变量?程序执行的本质就是一系列状态的 ...

  8. netty详解之io模型

    提起IO模型首先想到的就是同步,异步,阻塞,非阻塞这几个概念.每个概念的含义,解释,概念间的区别这些都是好理解,这里深入*nix系统讲一下IO模型. 在*nix中将IO模型分为5类. Blocking ...

  9. Cocos2d-x 3.2Lua演示样例UserDefaultTest(用户默认配置)

    Cocos2d-x 3.2演示样例UserDefaultTest(用户默认配置) 本篇博客介绍Cocos2d-x 3.2演示样例中的UserDefaulstTest,我们在开发中可能须要用到一些默认配 ...

  10. recover all files with git

    leon@DGLIRUAN2 /F/linux/android/leon/workspace/AngoWidget (master) $ git log commit 2f847e3a858ecb2f ...