`
vivus
  • 浏览: 116261 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring: No unique bean of type [] is defined: expected single bean but found 0:

    博客分类:
  • java
 
阅读更多
通过ApplicationContext.getBean(Class<T>)方法获取bean时报以下错:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.uih.anyi.mois.server.impl.InfusionServiceImpl] is defined: expected single bean but found 0:
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:276)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1113)

经查,是因为spring配置文件(applicationContext.xml)里配置了aop导致。
修复办法:
将<aop:config>改为<aop:config proxy-target-class="true">。
具体原因有待分析。

参考:
http://stackoverflow.com/questions/8028849/spring-aop-batch-retry-exception-expected-single-bean-but-found-0/8032665#8032665

http://stackoverflow.com/questions/841231/fixing-beannotofrequiredtypeexception-on-spring-proxy-cast-on-a-non-singleton-be

http://forum.springsource.org/showthread.php?66083-BeanNotOfRequiredTypeException-using-ServiceLocatorFactoryBean-and-Transactional
引用
To be clear: using 'proxy-target-class="true"' on <tx:annotation-driven/>,
<aop:aspectj-autoproxy/> or <aop:config/> elements will force the use of CGLIB
proxies for all three of them.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics