簡體   English   中英

Spring bean無法解析org.joda.time.DateTime的構造函數

[英]Spring bean unable to resolve constructor for org.joda.time.DateTime

我正在使用spring作為org.joda.time.DateTime構造函數注入

<bean id="myDateTime" class="org.joda.time.DateTime">
    <constructor-arg type="java.lang.Long" value="${startDateTime:#{null}}" />
</bean>

startDateTime解析為1341571102000 但是我收到關於無法解析構造函數的錯誤

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)

org.joda.time.DateTime類沒有接受java.lang.Long的構造函數。 您可能要使用一個接受long的原始值。 為此,請嘗試為constructor-arg指定type="long"

但是,在未設置startDateTime情況startDateTime退為null的情況將不起作用。 我不確定這種回退的意圖是什么,但是如果要使用long構造函數,則需要以其他方式解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM