I have a config.properties file:
date_format="yyyy-MM-dd"
My springmvc-servlet.xml:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/config.properties</value>
</list>
</property>
</bean>
This is my controller class:
@Controller
@RequestMapping("/T")
public class Test extends BaseController
{
@Value("${date_format}")
private static final String format; // Here, I want a final String as a constant
@RequestMapping(value = "t2")
@ResponseBody
public String func(@RequestParam("date") @DateTimeFormat(pattern = format) Date date)
{
return date.toString();
}
}
I want to use @Value annotation on a final variable, which is used in the annotation @DateTimeFormat.
@DateTimeFormat requires a final String variable, this is why I need to use @Value on final variables. But it doesn't work currently. Any ideas?