Results 1 to 2 of 2

Thread: Autowire failure when upgrading to Spring 3.1.2 (from 3.1.1)

  1. #1
    Join Date
    Sep 2006
    Posts
    5

    Default Autowire failure when upgrading to Spring 3.1.2 (from 3.1.1)

    Hi everyone,

    currently I am facing a strange problem I am not really sure how to handle this properly.

    Just to give you some necessary background regarding our configuration:

    - Mixed XML and Java configuration style
    - Autowiring is "default"

    Due to confidentiality reasons I am just able to post modified code but still the following should demonstrate the problem:

    We have a class definition like the following

    Code:
    @Component
    @DependsOn("dataSource")
    class SomeProcedure extends StoredProcedure {
    ....
    
    	@Inject
    	@Named("dataSource") // we have many javax.sql.DataSource beans, so we need to qualify here
    	public void init(final DataSource dataSource) {
            }
    ....
    }
    Furthermore here is the excerpt from our configuration file:

    Code:
    <bean id="dataSource" factory-bean="jndiManager" factory-method="lookup">
    		<constructor-arg><util:constant static-field="...JNDIConstants.ABC"/></constructor-arg>
    </bean>
    ....
    
    <context:component-scan package"the package which contains SomeProcedure/>
    This is what the "jndiManager.lookup" signature looks like

    Code:
    public Object void lookup(String jndiName) {...}
    This above configuration runs well under Spring 3.1.1.

    After an upgrade to Spring 3.1.2 I am runnning into the following

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void SomeProcedure.init(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    I debugged intensively and might have found the reason for this exception.

    The following change
    https://github.com/SpringSource/spri...6448732732c152
    introduces a new "Cache by-type lookups in DefaultListableBeanFactory" which is not able to find my "dataSource" dependency.

    When "someProcedure" bean is to be autowired the appropriate candidates are resolved by type (javax.sql.DataSource). Unfortunately, the "dataSource" bean does not seem to be cached under the javax.sql.DataSource type key. Instead it is cached under its runtime type (org.apache.commons.dbcp.datasources.SharedPoolDat aSource).

    So when I change my dependency from javax.sql.DataSource to SharedPoolDataSource the exception no longer occurs. But I would not want to bind to a concrete implementation type.

    Hopefully someone has a helpful idea here.
    Would appreciate it very much.

    Regards
    dokmatik
    Last edited by dokmatik; Jul 24th, 2012 at 02:07 PM.

  2. #2
    Join Date
    Aug 2005
    Posts
    26

    Default Similar problem upgrading from 3.1.1 to 3.1.2

    Hi Folks -

    Just to add to this post, I just switched our pom to consume Spring 3.1.2.RELEASE instead of 3.1.1.RELEASE and suddenly an autowiring problem occurred. I suspect the reason that dokmatik presented above might explain our situation as well - the autowiring is somewhat complex and relies pretty heavily on Spring to determine bean construction order.

    If anyone has any new configuration options that we can alter that will allow us to use 3.1.2's other fixes, or has insight on what was fixed and indicates we've done something wrong in our initial config, I'd very much appreciate it.

    Thanks!
    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •