bean定義やアノテーションに#{...}という構文を使用して動的な値を利用できます。
例1は、user.timezoneというシステムプロパティの値を取得する例です。また、例2は、他のbeanの値を取得する例です。例3は、アノテーションを使用した例です。
例
<bean id="fooSample" class="xxx.FooSampleImpl"> <property name="timezone" value="#{ systemProperties['user.timezone'] }"/> </bean> |
<bean id="fooSample2" class="xxx.fooSample2Impl"> <property name="randomNumber" value="#{ T(java.lang.Math).random() * 100.0 }"/> </bean> <bean id="fooSample3" class="xxx.fooSample3Impl"> <property name="seed" value="#{ fooSample2.randomNumber }"/> </bean> |
public static class FooSampleImpl{ @Value("#{ systemProperties['user.timezone'] }") private String timezone; public void setTimezone (String timezone){ this.timezone = timezone; } public String getTimezone (){ return this.timezone; } } |