springmvc注入类 NoUniqueBeanDefinitionException: No qualifying bean of type [] is defined: expected single错误
2017-11-14 20:07
549 查看
在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,表明实际运行哪个实现类。
当有两个实现类时都标明@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>
相关文章推荐
- Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]
- Bean对象注入失败 .NoSuchBeanDefinitionException: No qualifying bean of type..
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.wan
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
- shiro错误 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- NoSuchBeanDefinitionException: No qualifying bean of type
- “NoSuchBeanDefinitionException: No qualifying bean of type”问题解决
- 关于dao层Bean注入失败报No qualifying bean of type [xxx.xxx.xxx.xxx] is defined错误的问题
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- NoSuchBeanDefinitionException: No qualifying bean of type ..
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.wei
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [
- NoSuchBeanDefinitionException: No qualifying bean of type 'net.shopxx.service.xxxService' available:
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.act
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.itca
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lin
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cui
- Spring的JUnit错误:NoSuchBeanDefinitionException: No unique bean of type,expected single matching bean but found 2 [dataSource1,data
- NoSuchBeanDefinitionException:No qualifying bean of type 解决方法