Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through
来源:互联网 发布:怎么打开mac的airplay 编辑:程序博客网 时间:2024/06/08 03:40
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through bean property 'userDAO': : No unique bean of type [inspur.democreen.dao.UserDAO] is defined: expected single matching bean but found 2: [userDAO, userDAO2]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [inspur.democreen.dao.UserDAO] is defined: expected single matching bean but found 2: [userDAO, userDAO2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:982)
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.doGetBean(AbstractBeanFactory.java:283)
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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
at inspur.democreen.service.UserServiceTest.testAdd(UserServiceTest.java:13)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [inspur.democreen.dao.UserDAO] is defined: expected single matching bean but found 2: [userDAO, userDAO2]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:621)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1076)
... 32 more
在测试用例中,打印出 主动注入的 类中属性值。
spring配置文件如下
<bean name="userDAO" class="inspur.democreen.dao.impl.UserDAOImpl">
<property name="daoId" value="1"></property>
</bean>
<bean name="userDAO2" class="inspur.democreen.dao.impl.UserDAOImpl">
<property name="daoId" value="2"></property>
</bean>
<bean id="userService" class="inspur.democreen.service.UserService"
scope="prototype" autowire="byType">
</bean>
由于
autowire="byType"
那么userDervice中的type(inspur.democreen.dao.impl.UserDAOImpl)有两个(userDAO,userDAO2)所以报出异常
注释一个,byType自动注入 测试用例通过。
释:这种自动注入用得较少,一般都不想用这种方式注入。
- Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through
- Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocatio
- Error creating bean with name 'hotWordServiceImpl': Unsatisfied dependency expressed through field '
- Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]:
- Error creating bean with name 'userLoginDAO' defined in class path resource [applicationContext.xml]
- 一、Error creating bean with name 'hsFactory' defined in class path resource [xxx.xml]:
- Bug--Error creating bean with name 'sessionFactory' defined in class path resource [data_context.xml
- Error creating bean with name 'cxf' defined in class path resource [META-INF/cxf/cxf.xml]
- Error creating bean with name 'bookBizImpl' defined in class path resource [applicationContext.xml]
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]:
- Error creating bean with name 'diaryDAO' defined in class path resource [applicationContext.xml]:
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean faile
- 解决错误Error creating bean with name 'MySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationC
- Error creating bean with name 'org.apache.cxf.wsdl.WSDLManager' defined in class path resource
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- 错误Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.
- Error creating bean with name \'claimVoucherInfoServiceImpl\' defined in class path resource [applic
- SQL Server 2005 创建到 Oracle10g 的链接服务器
- C中“##”符号的用法
- Linux 内核编译 —— make localmodconfig 简化内核配置流程
- 作业论文1 --- 对目前拍拍网的一些建议
- pipelined 函数
- Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through
- 2010最危险的编程错误
- SendDTMF
- 通用线程:POSIX 线程详解------------作者——Daniel Robbins
- 序列化Serializable(asp.net C#)
- 软件架构师应该知道的97件事
- try catch throw用法
- 命令行还是用户界面?
- 时间管理-有趣的数据