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