Announcement Announcement Module
Collapse
No announcement yet.
Problem passing null parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem passing null parameters

    The following definition works
    Code:
    	<bean id="jmxConnector" class="javax.management.remote.JMXConnectorFactory" factory-method="newJMXConnector">
    		<constructor-arg><ref bean="jmxUrl"/></constructor-arg>
    		<constructor-arg><bean class="java.util.HashMap"/></constructor-arg>
    	</bean>
    But

    Code:
    	<bean id="jmxConnector" class="javax.management.remote.JMXConnectorFactory" factory-method="newJMXConnector">
    		<constructor-arg><ref bean="jmxUrl"/></constructor-arg>
    		<constructor-arg><null/></constructor-arg>
    	</bean>
    fails with

    Code:
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'jmxConnectorServer' defined in file &#91;/usr/local/workspace/LinkBuilder/web/WEB-INF/applicationContext.xml&#93;&#58; Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException&#58; Cannot find matching factory method 'newJMXConnectorServer' on class class javax.management.remote.JMXConnectorServerFactory
    org.springframework.beans.factory.BeanDefinitionStoreException&#58; Cannot find matching factory method 'newJMXConnectorServer' on class class javax.management.remote.JMXConnectorServerFactory
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod&#40;AbstractAutowireCapableBeanFactory.java&#58;399&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;246&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;205&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;204&#41;
    I have the latest spring 1.1.1 installed.

    I presume this is a bug, or am I doing something wrong?

    thanks

  • #2
    Sometimes there is an ambiguity with arguments of a constructor which can't be solved by Spring. Do no assume that it tries with the very same order you specified in the configuration. It tries to change the order of the given arguments to match a constructor.
    Anyway, in your case, introducing a null value makes it ambigute and you can force the order using the attribute index of each constructor-arg, like
    Code:
     <constructor-arg index="0"><ref bean="jmxUrl"/></constructor-arg>
     <constructor-arg index="1"><bean class="java.util.HashMap"/></constructor-arg>
    HTH

    Olivier

    Comment


    • #3
      That did the trick

      thank you

      Comment

      Working...
      X