`

No unique bean of type [com.xxx.service.Ixxx] is defined: expected single matchi

 
阅读更多

 

 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.xxx.service.impl.TestxxxImpl': Unsatisfied dependency expressed through bean property 'xxx': : No unique bean of type [com.xxx.service.Ixxx] is defined: expected single matching bean but found 2: [xxxImpl, xxx]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.xxx.service.Ixxx] is defined: expected single matching bean but found 2: [xxxImpl, xxx]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1167)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1059)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
	at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:208)
	at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:183)
	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:103)
	at junit.framework.TestCase.runBare(TestCase.java:128)
	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
	at com.comwave.core.test.BaseDBTestCase.runBare(BaseDBTestCase.java:70)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	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 [com.xxx.service.Ixxx] is defined: expected single matching bean but found 2: [xxxImpl, xxx]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:796)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1152)
	... 20 more

 原因:

1.註解中有加,配置文件又有加bean,所以就出現兩個了

2.spring dbunit  

public class TestxxxImpl {
	protected Ixxx xxx;
        
        //(1)xxx的setter方法
}

  (2)配置中有加bean ,所以就出現兩個了

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics