S2SH整合注入@Autowired出现expected single matching bean but found 2: [iDAO, areaDAO]
异常信息如下:
2012-9-8 14:42:57 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaManager':
Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: protected com.cn.common.base.IDAO com.cn.common.base.ManagerImpl.iDAO; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type
[com.cn.common.base.IDAO] is defined: expected single matching bean but found 2: [iDAO, areaDAO]
?at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstanti
ation(AutowiredAnnotationBeanPostProcessor.java:243)
?at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean
(AbstractAutowireCapableBeanFactory.java:959)
?at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean
(AbstractAutowireCapableBeanFactory.java:472)
?at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run
(AbstractAutowireCapableBeanFactory.java:409)
?at java.security.AccessController.doPrivileged(Native Method)
?at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
(AbstractAutowireCapableBeanFactory.java:380)
?at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject
(AbstractBeanFactory.java:264)
?at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton
(DefaultSingletonBeanRegistry.java:222)
?at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean
(AbstractBeanFactory.java:261)
?at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:185)
?at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:164)
?at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons
(DefaultListableBeanFactory.java:429)
?at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization
(AbstractApplicationContext.java:728)
?at org.springframework.context.support.AbstractApplicationContext.refresh
(AbstractApplicationContext.java:380)
?at org.springframework.web.context.ContextLoader.createWebApplicationContext
(ContextLoader.java:255)
?at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
?at org.springframework.web.context.ContextLoaderListener.contextInitialized
(ContextLoaderListener.java:45)
?at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
?at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
?at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
?at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
?at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
?at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
?at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
?at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
?at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
?at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
?at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
?at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
?at org.apache.catalina.core.StandardService.start(StandardService.java:516)
?at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
?at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
?at java.lang.reflect.Method.invoke(Method.java:597)
?at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
?at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected
com.cn.common.base.IDAO com.cn.common.base.ManagerImpl.iDAO; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type
[com.cn.common.base.IDAO] is defined: expected single matching bean but found 2: [iDAO, areaDAO]
?at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.in
ject(AutowiredAnnotationBeanPostProcessor.java:435)
?at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields
(InjectionMetadata.java:105)
?at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstanti
ation(AutowiredAnnotationBeanPostProcessor.java:240)
?... 40 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type
[com.cn.common.base.IDAO] is defined: expected single matching bean but found 2: [iDAO, areaDAO]
?at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency
(DefaultListableBeanFactory.java:621)
?at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.in
ject(AutowiredAnnotationBeanPostProcessor.java:412)
?... 42 more
2012-9-8 14:42:57 org.apache.catalina.core.ApplicationContext log
说明如下:有一个公共的dao层接口(IDAO)及其实现类(DAOImpl)和service层接口(IManager)及其实现类(ManagerImpl)
IDAO.java如下:
public interface IDAO {
? public void add(Object obj);
}
DAOImpl.java如下:
public class DAOImpl implements IDAO {
? @Autowired
? protected HibernateTemplate ht;
? public void add(Object obj) {
?? ht.save(obj);
? }
}
IManager.java如下:
public interface IManager {
? public void add(Object obj);
}
ManagerImpl.java如下:
public class ManagerImpl implements IManager {
?@Autowired
?protected IDAO iDAO;
?
? public void add(Object obj) {
?? iDAO.add(obj);
? }
}
现在有一个area类,以及dao层接口实现类,service层接口实现类,分别继承以上相应的接口或者类,AreaManagerImpl.java
代码如下:
?public class AreaManagerImpl extends ManagerImpl implements IAreaManager {
? @Autowired
? private IAreaDAO areaDAO;
? //此方法为AreaDAO接口方法
? public List<Area> getAreaListByFather(Integer father) {
?? return areaDAO.getAreaListByFather(father);
? }
}
===========================主要JAVA文件结束=====================
spring配置:
<context:annotation-config />
<bean id="iDAO" />
<bean id="areaManager" />
<bean id="areaDAO" />
启动tomcat后报以上的异常,求各位大神,小弟不胜感激,谢谢了