model - Spring: How do I set the pattern of a @DateTimeFormat from a properties file? -


i'm using spring 3.1.1.release. have model submit 1 of controllers. in it, following field

@datetimeformat(pattern = "#{appprops['class.date.format']}") private java.util.date startdate; 

however, above doesn't work (the el isn't being interpreted), in far every time submit form, error. if use following

@datetimeformat(pattern="yyyy-mm-dd") private java.util.date startdate; 

everything works fine. ideally, i'd drive pattern properties file. possible , if so, what's correct syntax?

  • dave

i use propertysourcesplaceholderconfigurer read system properties. can use syntax resolve placeholders : ${prop.name}.

your annotated filed should work then:

@datetimeformat(pattern = "${class.date.format}") private java.util.date startdate; 

to configure propertysourcesplaceholderconfigurer application in xml, try this:

<bean class="org.springframework.beans.factory.config.propertysourcesplaceholderconfigurer">   <property name="location">     <list>       <value>classpath:myprops.properties</value>     </list>   </property>   <property name="ignoreunresolveableplaceholders" value="true"/> </bean> 

or, javaconfig:

@bean public static propertysourcesplaceholderconfigurer propertysourcesplaceholderconfigurer() {     //note static method! important!!     propertysourcesplaceholderconfigurer configurer = new propertysourcesplaceholderconfigurer();     resource[] resources = new classpathresource[] { new classpathresource("myprops.properties")};     configurer.setlocations(resources);     configurer.setignoreunresolvableplaceholders(true);     return configurer; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -