How to reference a constant in Spring Expression Language
10,678
The special 'T' operator can be used to specify an instance of java.lang.Class (the 'type'). Static methods are invoked using this operator as well.
Try the code below.
<property name='typeOf' value='#{typeOfBuilder.getKeyFor(T(some.package.Constants).KEY_FOR_OPEN_DATE).getId()}'/>
Author by
chiperortiz
Java Lover I'm from Venezuela. Rock 'n' Roll fan by 23 years. MLB Major League Baseball fan by 21 years... In love with Java 8 and JRebel.
Updated on July 23, 2022Comments
-
chiperortiz almost 2 years
i am quite new to Spring and i have a bean declaration as follows.
<bean id="mybean" class="" scope="prototype"> <property name='typeOf' value='#{typeOfBuilder.getKeyFor("OPEN_DATE").getId()}'/> </bean>
typeOf
is a type of Integer which is the key of another table whichtypeOfBuilder
builds byKey
which isOPEN_DATE
in this case.this code works OK but have a limitation.
OPEN_DATE
is a constant in aNON-MANAGE Spring Bean
something like follows.public final class Constants { public final static String KEY_FOR_OPEN_DATE = "OPEN_DATE"; }
and is strongly recommend to be able to reference to it!!.
something like this.
<util:constant id="PATH_TO_CONSTANT" static-field="myPath"/> <property name='typeOf' value='#{typeOfBuilder.getKeyFor(PATH_TO_CONSTANT).getId()}'/>
any help is hugely appreciate.