I'm having a problem with Spring and constructor injection. I want to create dynamically objects with a name (String
) and special id (long
).
But when the spring.xml file is loaded an exception occurs.
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'someBean' defined in class path resource [spring.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [long]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?
My spring.xml:
<bean id="someBean" class="someClass" >
<constructor-arg index="0" type="java.lang.String" value=""/>
<constructor-arg index="1" type="long" value=""/>
</bean>
</beans>
So what's wrong there? The constructor-arg has index 1 (and not 0, as the exception says)
In the constructor arguments you can use either a primitive type long
and value 0
, or a wrapper type java.lang.Long
and an empty value. Also, to keep things under control, I would set a value of the second argument explicitly to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With