这就是我试图在@Component类中注入日期的方法。
@Value("${new java.text.SimpleDateFormat(\"yyyyMMdd\").parse(\"${PROP_DATE}\")}")
Date myDate;
日期在属性文件中指定为String:
PROP_DATE=20110421
我收到此错误。我究竟做错了什么?有没有其他方法来注入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")'
答案 0 :(得分:9)
使用#{new java.text.SimpleDateFormat(\"yyyyMMdd\").parse(\"${PROP_DATE}\")}
将过程值与spEL