开发者

Setting values from a class to Spring context file

开发者 https://www.devze.com 2022-12-13 19:48 出处:网络
We usually define some beans with their properties in the Spring context file and write some setter methods in the class.

We usually define some beans with their properties in the Spring context file and write some setter methods in the class.

Let's say I want to do the opposite. I have开发者_如何学Go a bean in the context file and want to declare some properties from the class, or initialize values of declared properties in the context from the class. How do I do that?


You will need to define a BeanFactoryPostProcessor. Bean factory post processors have the ability to alter or add to the context before spring fully initializers.

For more information please see the spring manual chapter for this: Chapter 3


You could either the util Spring XML namespace util:property-path or a PropertyPathFactoryBean to reference a bean's property as value for a property.

Please note that the property you refer to does not need to be defined by Spring, it can be set in code, like your question suggests you want to do

0

精彩评论

暂无评论...
验证码 换一张
取 消