views:

141

answers:

2

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 wanna do the opposite. I have 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?

+1  A: 

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

Gennadiy
+1  A: 

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

Fried Hoeben