4
我已成功配置Spring自动装配,除了java.util.Properties的实例之外的所有内容。Spring Autowire属性对象
当我自动装配一切与注释:
@Autowired private SomeObject someObject;
它工作得很好。
但当我尝试这个办法:
@Autowired private Properties messages;
与此配置:
<bean id="mybean" class="com.foo.MyBean" >
<property name="messages">
<util:properties location="classpath:messages.properties"/>
</property>
</bean>
我的错误(相关线路只):
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean' defined in class path resource [application.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'messages' of bean class [com.foo.MyBean]: Bean property 'messages' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Wheras,如果我尝试它采用了一种很好的老式二传手法,Spring很高兴地接通了它:
public void setMessages(Properties p) { //this works
this.messages = p;
}
当我尝试自动装载属性对象时,我做错了什么?
谢谢=现在为我工作,id =“消息”添加到属性标记。 – NickJ 2013-03-22 17:46:53