我可以在Spring3.2forJava中使用@Value解析和注入日历项吗?

我可以在Spring3.2forJava中使用@Value解析和注入日历项吗?,java,spring,properties,annotations,spring-el,Java,Spring,Properties,Annotations,Spring El,我有一个应用程序,它使用springs@PropertySource创建一个从我的属性文件解析的bean 稍后,我尝试使用@Value将其中一些值注入到字段中 属性文件: # StartDate in format yyyy-MM-dd startDate=2013-12-05 # EndDate in format yyyy-MM-dd endDate=2013-12-06 BeanConfig: @Configuration @PropertySource("classpath:wfmCo

我有一个应用程序,它使用springs@PropertySource创建一个从我的属性文件解析的bean

稍后,我尝试使用@Value将其中一些值注入到字段中

属性文件:

# StartDate in format yyyy-MM-dd
startDate=2013-12-05
# EndDate in format yyyy-MM-dd
endDate=2013-12-06
BeanConfig:

@Configuration
@PropertySource("classpath:wfmConfig.properties")
public class WfmConfig {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}
注射:

@Value("#(Calendar.getInstance().setTime(new SimpleDateFormat(\"yyyy-MM-    dd\").parse(\"$endDate}\"))}")
private Calendar endDate;
如前所述,这种spEL解析对于日期对象非常有效


为什么这不起作用?有没有办法在这里使用日历而不是日期?

设置时间的结果是无效的,而不是日历。使用@Value注释时,正常弹簧转换器仍处于激活状态。您可以创建一个StringToCalendarConverter来进行转换。谢谢。这是一个明显的错误,但我没有运气定义一个方法来做到这一点。它只是在向我尖叫,这种新方法无法定位。我在它周围工作,用Date代替它,它有一个本机注入器。