Issue
I am injecting constructor for org.joda.time.DateTime
using spring as
<bean id="myDateTime" class="org.joda.time.DateTime">
<constructor-arg type="java.lang.Long" value="${startDateTime:#{null}}" />
</bean>
The startDateTime is resolved as 1341571102000
. But I'm getting error regarding unable to resolve constructor
Cannot resolve reference to bean 'myDateTime' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDateTime' defined in URL [file:/path/to/spring-configuration/application-config.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
Solution
The org.joda.time.DateTime
class does not have a constructor that accepts a java.lang.Long
. You probably want to use the one that accepts a primitive long
. To do that, try specifying type="long"
for the constructor-arg
.
However, the fallback to null
in case startDateTime
is not set will not work in that case. I'm not sure what your intention with that fallback is, but you need to solve it some other way if you are to use the long
constructor.
Answered By - K Erlandsson
Answer Checked By - Senaida (JavaFixing Volunteer)