使用@Value注释注入日期

sha*_*rma 3 spring annotations date code-injection

这就是我试图将一个日期注入@Component类的方法.

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

日期在属性文件中指定为String:

PROP_DATE=20110421
Run Code Online (Sandbox Code Playgroud)

我收到这个错误.我究竟做错了什么?有没有其他方法来注入Date属性?谢谢.

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")'
Run Code Online (Sandbox Code Playgroud)

Luc*_*cci 12

使用#{new java.text.SimpleDateFormat(\"yyyyMMdd\").parse(\"${PROP_DATE}\")}与SPEL过程值