Results 1 to 3 of 3

Thread: Problem passing null parameters

  1. #1
    Join Date
    Oct 2004
    Posts
    22

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    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

  3. #3
    Join Date
    Oct 2004
    Posts
    22

    Default

    That did the trick

    thank you

Similar Threads

  1. Replies: 2
    Last Post: Oct 17th, 2005, 08:41 PM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  3. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  4. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  5. Strange Data Access Error
    By webifyit in forum Data
    Replies: 2
    Last Post: Dec 28th, 2004, 11:06 AM

Posting Permissions

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