【问题标题】:Spring bean unable to resolve constructor for org.joda.time.DateTimeSpring bean 无法解析 org.joda.time.DateTime 的构造函数
【发布时间】:2015-07-06 11:01:49
【问题描述】:

我正在使用 spring as 为 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)

【问题讨论】:

  • 你能解释一下你想用那个豆子在这里拉什么吗?

标签: java spring dependency-injection jodatime spring-bean


【解决方案1】:

org.joda.time.DateTime 类没有接受java.lang.Long 的构造函数。您可能想要使用接受原始long 的那个。为此,请尝试为 constructor-arg 指定 type="long"

但是,在未设置 startDateTime 的情况下回退到 null 在这种情况下将不起作用。我不确定您使用该回退的意图是什么,但是如果您要使用 long 构造函数,则需要以其他方式解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 2015-05-05
    • 2017-02-28
    • 2016-09-18
    • 1970-01-01
    相关资源
    最近更新 更多