Results 1 to 3 of 3

Thread: MethodInvokingFactoryBean error in 2.0.3

  1. #1
    Join Date
    Sep 2006
    Posts
    2

    Default MethodInvokingFactoryBean error in 2.0.3

    Hi all,

    I'm currently migrating from 1.2.8 and came across this error while using MethodInvokingFactoryBean to read a property from a properties file:

    Code:
    ...
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties' defined in class path resource [com/someapp/application/spring-inc-txn-mgmt.xml]: Cannot create inner bean 'org.springframework.beans.factory.config.MethodInvokingFactoryBean#5c205c20' of type [org.springframework.beans.factory.config.MethodInvokingFactoryBean] while setting constructor argument with key [TypedStringValue: value [hibernate.connection.url], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.MethodInvokingFactoryBean#5c205c20' defined in class path resource [com/someapp/application/spring-inc-txn-mgmt.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: $Proxy52.getProperty(java.lang.String)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:228)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:111)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:324)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:140)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:320)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:90)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:781)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:723)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:390)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
    	at com.someapp.listener.ApplicationSetupContext.initialiseSpring(ApplicationSetupContext.java:184)
    	... 134 more
    Caused by: 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.MethodInvokingFactoryBean#5c205c20' defined in class path resource [com/someapp/application/spring-inc-txn-mgmt.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: $Proxy52.getProperty(java.lang.String)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1113)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:221)
    	... 150 more
    Caused by: 
    java.lang.NoSuchMethodException: $Proxy52.getProperty(java.lang.String)
    	at java.lang.Class.throwNoSuchMethodException(Class.java:275)
    	at java.lang.Class.getMethod(Class.java:780)
    	at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:180)
    	at org.springframework.beans.factory.config.MethodInvokingFactoryBean.afterPropertiesSet(MethodInvokingFactoryBean.java:148)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1143)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1110)
    	... 152 more
    After receving this error, I decided to test the above using the sample configuration code provided in the Javadoc documentation for
    org.springframework.beans.factory.config.MethodInv okingFactoryBean (copied verbatim):

    Code:
      <bean id="sysProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass"><value>java.lang.System</value></property>
        <property name="targetMethod"><value>getProperties</value></property>
      </bean>
    
      <bean id="javaVersion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject"><ref local="sysProps"/></property>
        <property name="targetMethod"><value>getProperty</value></property>
        <property name="arguments">
          <list>
            <value>java.version</value>
          </list>
        </property>
      </bean>
    And this is the error I received:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'javaVersion' defined in class path resource [com/someapp/application/spring-inc-txn-mgmt.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: $Proxy53.getProperty(java.lang.String)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1113)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:281)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
    	at com.someapp.listener.SetupContext.initialiseSpring(ApplicationSetupContext.java:184)
    	... 134 more
    Caused by: 
    java.lang.NoSuchMethodException: $Proxy53.getProperty(java.lang.String)
    	at java.lang.Class.throwNoSuchMethodException(Class.java:275)
    	at java.lang.Class.getMethod(Class.java:780)
    	at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:180)
    	at org.springframework.beans.factory.config.MethodInvokingFactoryBean.afterPropertiesSet(MethodInvokingFactoryBean.java:148)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1143)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1110)
    	... 143 more
    Has anyone encountered this issue before? Alternatively, can anyone suggest a workaround?

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    I cannot reproduce this problem with Spring 2.0.3. What I find curious is that "sysProps" seems to be a proxy in your case. Could it be that there is an interference from autoproxying?

    Regards,
    Andreas

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    It's usually useful to see the whole applicationContext here. There does seem to be some proxying, but from the snippet it's not clear where this is coming from.

Posting Permissions

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