有没有办法在Spring Context中连接Date.getTime()的值?

时间:2016-02-29 15:19:59

标签: java spring

我想知道有没有办法在spring上下文中连接Date.getTime()值。 这是我的下面的豆。

<bean id="date" class="java.util.Date/>

我可以通过任何方式连接date.getTime()的值吗?

1 个答案:

答案 0 :(得分:0)

试试这个SpEL expressions in XML configuration

可以使用如下所示的表达式设置属性或构造函数-arg值。

<bean id="numberGuess" class="org.spring.samples.NumberGuess">
<property name="randomNumber" value="#{ T(java.lang.Math).random() * 100.0 }"/>

<!-- other properties -->
</bean>

变量systemProperties是预定义的,因此您可以在表达式中使用它,如下所示。请注意,您不必在此上下文中使用#符号为预定义变量添加前缀。

<bean id="taxCalculator" class="org.spring.samples.TaxCalculator">
<property name="defaultLocale" value="#{ systemProperties['user.region'] }"/>

<!-- other properties -->
</bean>

您也可以按名称引用其他bean属性,例如。

<bean id="numberGuess" class="org.spring.samples.NumberGuess">
<property name="randomNumber" value="{ T(java.lang.Math).random() * 100.0 }"/>

<!-- other properties -->
</bean>
<bean id="shapeGuess" class="org.spring.samples.ShapeGuess">
<property name="initialShapeSeed" value="{ numberGuess.randomNumber }"/>

<!-- other properties -->
</bean>