Spring - using static final fields (constants) for bean initialization
Something like this (Spring 2.5)
<bean id="foo" class="Bar"> <property name="myValue"> <util:constant static-field="java.lang.Integer.MAX_VALUE"/> </property></bean>
Where util
namespace is from xmlns:util="http://www.springframework.org/schema/util"
But for Spring 3, it would be cleaner to use the @Value
annotation and the expression language. Which looks like this:
public class Bar { @Value("T(java.lang.Integer).MAX_VALUE") private Integer myValue;}
Or, as an alternative, using Spring EL directly in XML:
<bean id="foo1" class="Foo" p:someOrgValue="#{T(org.example.Bar).myValue}"/>
This has the additional advantage of working with namespace configuration:
<tx:annotation-driven order="#{T(org.example.Bar).myValue}"/>
don't forget to specify the schema location..
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"></beans>