Author
spring property initialization with java property
Kazimierz Trzonek
Greenhorn
Joined: Oct 08, 2008
Posts: 21
Hi, I would like to initialize my byte property with java constant, is it possible? how can I do it? where is it explained? i checked spring reference, and there's no such example (http://static.springframework.org/spring/docs/2.5.x/reference/beans.html ). I would like sth like: <property name="whenExhaustedAction" > <value> org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_FAIL </value> </property>
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
You could use a FieldRetrievingFactoryBean to retrieve the static WHEN_EXHAUSTED_FAIL.
[My Blog]
All roads lead to JavaRanch
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17228
posted Oct 09, 2008 07:36:00
0
Actually it is much easier than that. The util namespace can access a constant for you. I believe it is <util:constant> and tell it which constant to use. Here is the documentation link http://static.springframework.org/spring/docs/2.5.x/reference/xsd-config.html#xsd-config-body-schemas-util-constant You will notice the first example is the same that Christophe posted, then the next code example is with using <util:constant> to make it easier. Mark [ October 09, 2008: Message edited by: Mark Spritzler ]
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kazimierz Trzonek
Greenhorn
Joined: Oct 08, 2008
Posts: 21
Thank You, both solutions work.
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
Thanks Mark, I didn't know about util:constant. "Bolek Lolek", please check your privates messages.
subject: spring property initialization with java property