Can I use @Value to parse and inject a Calendar item in Spring 3.2 for Java?

486 Views Asked by At

I have an application that uses springs @PropertySource to create a bean parsed from my property-file.

Later I try to inject some of those values into a field using @Value.

property-file:

# 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();
    }
}

Injection:

@Value("#(Calendar.getInstance().setTime(new SimpleDateFormat(\"yyyy-MM-    dd\").parse(\"$endDate}\"))}")
private Calendar endDate;

This spEL-parsing works wonderful for Date-objects as stated here.

Why doesnt this work? Is there any way to utilize Calendar here instead of Date?

0

There are 0 best solutions below