Error creating bean with name 'empServiceImpl' defined in file [D:\Workspaces\My

<!--  当有多个相同类型的bean,会出现bug如下:

   org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empServiceImpl' defined in file [D:\Workspaces\MyEclipse 8.6\20110419_01\bin\applicationContext.xml]: Unsatisfied dependency expressed through bean property 'companyAddress': : No unique bean of type [cn.csdn.service.AddressServiceImpl] is defined: expected single matching bean but found 2: [homeAddressServiceImpl, addressServiceImpl]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [cn.csdn.service.AddressServiceImpl] is defined: expected single matching bean but found 2: [homeAddressServiceImpl, addressServiceImpl]

     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$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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

     at cn.csdn.service.App.test(App.java:12)

     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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)

     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)

     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)

     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)

     at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)

     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

     at org.junit.runners.ParentRunner.run(ParentRunner.java:220)

     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

     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 [cn.csdn.service.AddressServiceImpl] is defined: expected single matching bean but found 2: [homeAddressServiceImpl, addressServiceImpl]

     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:621)

     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1076)

     ... 40 more

   -->

<!--

   byName

   byType

   在使用的过程中必须保证bean能够初始化,否则的话会出现bug

   如果有默认的无参数的构造器就不需要多余的配置

  如果有带有参数的构造器,那在bean的配置中必须配置器初始化的参数或者在bean中添加无参数的构造器

 dependency-check="objects":依赖对象检查 ,如果对象不存在就会出现bug

 dependency-check:

    none:没有依赖检查

    simple(除了协作者)原始数据、集合执行依赖检查

    objects仅对协作者的依赖检查

    all 所有

 -->

你可能感兴趣的:(java,eclipse,bean,MyEclipse,JUnit)