2013-08-05 52 views
2

這就是我試圖向@Component類注入日期的方式。使用@Value註解的注入日期

@Value("${new java.text.SimpleDateFormat(\"yyyyMMdd\").parse(\"${PROP_DATE}\")}") 
Date myDate; 

日期指定爲屬性的字符串文件:

PROP_DATE=20110421 

我得到這個錯誤。我究竟做錯了什麼?有沒有其他的方式來注入日期屬性?謝謝。

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ccc': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.Date aaa.bbb.ccc.myDate; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'new java.text.SimpleDateFormat("yyyyMMdd").parse("20110421")' 

回答

9

使用#{new java.text.SimpleDateFormat(\"yyyyMMdd\").parse(\"${PROP_DATE}\")}與SPEL

+0

這工作過程中的價值。謝謝。 –