Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.0 M1
    • Fix Version/s: 3.0 M2
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      The following code works with Spring 2.5.x but does not work with 3.0 M1

      Xml:
      <util:properties id="clientProperties" location="classpath:/com/pictage/client/client.properties"/>

      Java Code:

      @Autowired
      public DirectoryDaoJdbc(@Qualifier("v3DataSource")javax.sql.DataSource v3DataSource, @Qualifier("v3photoDataSource")javax.sql.DataSource v3photoDataSource, EventDao eventDao, @Qualifier("clientProperties") Properties clientProperties)

      { v3SimpleJdbcTemplate = new LoggingSimpleJdbcTemplate(v3DataSource); v3photoSimpleJdbcTemplate = new LoggingSimpleJdbcTemplate(v3photoDataSource); this.eventDao = eventDao; this.clientProperties = clientProperties; }

      Exception:

      org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'directoryService' defined in file [C:\Users\smurphy\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\photographer\WEB-INF\classes\com\pictage\directory\bus\DirectoryService.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.pictage.directory.dao.DirectoryDao]: : Error creating bean with name 'directoryDaoJdbc' defined in file [C:\Users\smurphy\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\photographer\WEB-INF\classes\com\pictage\directory\dao\jdbc\DirectoryDaoJdbc.class]: Unsatisfied dependency expressed through constructor argument with index 3 of type [java.util.Properties]: : No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'directoryDaoJdbc' defined in file [C:\Users\smurphy\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\photographer\WEB-INF\classes\com\pictage\directory\dao\jdbc\DirectoryDaoJdbc.class]: Unsatisfied dependency expressed through constructor argument with index 3 of type [java.util.Properties]: : No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:582)
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:922)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:833)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:442)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:411)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:271)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:268)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:470)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:719)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:378)
      at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:254)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:198)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
      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.start(ContainerBase.java:1045)
      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.UnsatisfiedDependencyException: Error creating bean with name 'directoryDaoJdbc' defined in file [C:\Users\smurphy\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\photographer\WEB-INF\classes\com\pictage\directory\dao\jdbc\DirectoryDaoJdbc.class]: Unsatisfied dependency expressed through constructor argument with index 3 of type [java.util.Properties]: : No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:582)
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:922)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:833)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:442)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:411)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:271)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:268)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:721)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:660)
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:612)
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:575)
      ... 32 more
      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [clientProperties, systemProperties]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:671)
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:612)
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:575)
      ... 47 more

        Activity

        Hide
        Juergen Hoeller added a comment -

        It would be great if you could isolate this into a unit test... Our general qualifier unit tests still pass in 3.0 M1.

        Juergen

        Show
        Juergen Hoeller added a comment - It would be great if you could isolate this into a unit test... Our general qualifier unit tests still pass in 3.0 M1. Juergen
        Hide
        Scott Murphy added a comment -

        This appears to just be happening with Properties files only. If I remove the properties from the constructor, the qualifier still works for my datasource.

        Show
        Scott Murphy added a comment - This appears to just be happening with Properties files only. If I remove the properties from the constructor, the qualifier still works for my datasource.
        Hide
        Scott Murphy added a comment -

        is systemProperties new to Spring 3? If so, that is probably what is causing the confusion.

        Show
        Scott Murphy added a comment - is systemProperties new to Spring 3? If so, that is probably what is causing the confusion.
        Hide
        Scott Murphy added a comment -

        Okay, I created a Unit test for you that fails:
        here is the exception:

        SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@193a66f] to prepare test instance [test.QualifierTest@93d6bc]
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test.QualifierTest': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.Properties test.QualifierTest.testProperties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:259)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:955)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:332)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:127)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:85)
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:231)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:95)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:139)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
        Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.Properties test.QualifierTest.testProperties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:462)
        at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:256)
        ... 18 more
        Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:671)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:439)
        ... 20 more
        java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:146)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

        Show
        Scott Murphy added a comment - Okay, I created a Unit test for you that fails: here is the exception: SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@193a66f] to prepare test instance [test.QualifierTest@93d6bc] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test.QualifierTest': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.Properties test.QualifierTest.testProperties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:259) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:955) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:332) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:127) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:85) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:95) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:139) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.Properties test.QualifierTest.testProperties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:462) at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:256) ... 18 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.util.Properties] is defined: expected single matching bean but found 2: [testProperties, systemProperties] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:671) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:439) ... 20 more java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:146) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
        Hide
        Scott Murphy added a comment -

        I have attached the unit test

        Show
        Scott Murphy added a comment - I have attached the unit test
        Hide
        Scott Murphy added a comment -

        JUnit test that shows @Qualifier fails

        Show
        Scott Murphy added a comment - JUnit test that shows @Qualifier fails
        Hide
        Scott Murphy added a comment -

        Hey Juergen,

        Once you fix this, am I going to have to wait for the M2 release to use it? Or is there a 3.0.0.M2-SNAPSHOT release I can get access too via Maven?

        Show
        Scott Murphy added a comment - Hey Juergen, Once you fix this, am I going to have to wait for the M2 release to use it? Or is there a 3.0.0.M2-SNAPSHOT release I can get access too via Maven?
        Hide
        Juergen Hoeller added a comment -

        This is resolved for M2 now: Any singletons registered, including default singletons such as "systemProperties", will be fully matched according to their qualifiers as well - and not simply considered a default match like before.

        Juergen

        Show
        Juergen Hoeller added a comment - This is resolved for M2 now: Any singletons registered, including default singletons such as "systemProperties", will be fully matched according to their qualifiers as well - and not simply considered a default match like before. Juergen

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Scott Murphy
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              5 years, 10 weeks, 2 days ago