public class Student {
private Date birth;
public void setBirth(Date birth) {
this.birth = birth;
}
@Override
public String toString() {
return "Student{" +
"birth=" + birth +
'}';
}
}
public class DateFactoryBean implements FactoryBean<Date> {
private String strDate;
public DateFactoryBean(String strDate) {
this.strDate = strDate;
}
@Override
public Date getObject() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(strDate);
return date;
}
@Override
public Class<?> getObjectType() {
return null;
}
}
<bean id="dateFactoryBean" class="com.powernode.spring6.bean.DateFactoryBean">
<constructor-arg name="strDate" value="1998-08-05"/>
</bean>
<bean id="student" class="com.powernode.spring6.bean.Student">
<property name="birth" ref="dateFactoryBean"/>
</bean>