It looks like you are trying to call the setter method in the first case. When you create a property element inside a bean, it will use setter injection to enter the bean. (You do not have a setter in your case, so that it throws an error)
If you want to auto-install it, delete this:
<property name="messages"> <util:properties location="classpath:messages.properties"/> </property>
From the definition of bean, as this will try to call the setMessages method.
Instead, simply define the bean properties in the context file separately for MyBean :
<bean id="mybean" class="com.foo.MyBean" /> <util:properties location="classpath:messages.properties"/>
Then it should automatically flash.
Please note that this also means that you can add this: @Autowired private Properties messages; in any Spring managed bean to use the same property object in other classes.
cowls source share