I have a class with a constructor with 4 Integer args. It is configured in spring xml like so:
<bean id="mySearchService" class="app.service.MySearchService"
c:maxConnectionsPerHost="${maxConnectionsPerHost}"
c:maxTotalConnections="${maxTotalConnections}"
c:connectionTimeout="${connectionTimeout}"
c:soTimeout="${soTimeout}" />
My properties file has:
maxConnectionsPerHost=50
maxTotalConnections=50
connectionTimeout=500
soTimeout=100
But I get the following error:
Error creating bean with name ‘mySearchService’ defined in class path resource [applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.lang.Integer]: Ambiguous constructor argument types – did you specify the correct bean references as constructor arguments?
This works if I use <constructor-arg value="..." /> so I’m wondering if the c-namespace does not to type conversions in the same way as constructor-arg.
I’m pretty sure this is the reason:
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-ctor-arguments-resolution
All the arguments are of the same type, and probably the parameter names are not available at runtime (no debug info). I can either provide indexes OR use the
@ConstructorPropertiesannotation to make the names visible.