Announcement Announcement Module
Collapse
No announcement yet.
Validation of constructor-arg 'type' attribute Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation of constructor-arg 'type' attribute

    Is there any validation on the type attribute of a bean's contructor argument? I think that there should be and an exception should be raised when the target 'type' cannot be converted from the value/ref of the object specified.

    Code:
    <bean class="java.net.InetSocketAddress">
        <constructor-arg value="fred" type="String" />
        <constructor-arg value="bob" type="int" />
    </bean>
    Using Spring 3.1.0 in practice, fred and bob are parameterised with ${} and should have been injected at runtime. The error below is produced and based this, I tried to resolve an issue that didn't exist.

    Code:
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	... 57 common frames omitted
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'java.net.InetSocketAddress#19e41e62' defined in class path resource [META-INF/spring/applicationContext-test.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
Working...
X