File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg index="0">
<bean class="java.text.SimpleDateFormat">
<constructor-arg><value>M/d/yy</value></constructor-arg>
</bean>
</constructor-arg>
<constructor-arg index="1"><value>true</value></constructor-arg>
</bean>
</entry>
</map>
</property>
</bean>
<bean id="startEndDatesBean" class="StartEndDatesBean">
<property name="startDate"><value>10/09/2001</value></property>
<property name="endDate"><value>10/26/2008</value></property>
</bean>
</beans>
File: Main.java
import java.util.Date;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"context.xml");
StartEndDatesBean startEnd = (StartEndDatesBean) ctx.getBean("startEndDatesBean");
}
}
class StartEndDatesBean {
Date startDate;
Date endDate;
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getStartDate() {
return startDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Date getEndDate() {
return endDate;
}
}
Download: Spring-PropertiesSettingDate.zip( 2,893 k)