Spring 元素必须指定一个ref或值
问题描述:
我遇到了Spring和构造函数注入的问题。我想用名称(String
)和特殊ID(long
)动态创建对象。Spring <constructor-arg>元素必须指定一个ref或值
但是,当加载spring.xml文件时会发生异常。
在线程“主” java.lang.ExceptionInInitializerError
异常引起的:org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建具有名称豆“someBean”类路径资源定义[弹簧。 xml]:通过类型为[long]的索引0的构造函数参数表示的不满意的依赖项:模糊的构造函数参数类型 - 是否将正确的bean引用指定为构造函数参数?
我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>
那么,什么是错的呢?构造函数精氨酸具有索引1(和不为0,作为异常说)
您是否尝试过使用'type =“java.lang.Long”'? – LaurentG
是的,我也试过。我也删除了索引。但没有改进 – smsnheck
你应该也分享你的构造函数真的看起来像 – KNU