Properties Setting: Date : Properties Injection « Spring « Java Tutorial






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)








28.5.Properties Injection
28.5.1.Fill Map
28.5.2.Fill Set
28.5.3.Fill Properties
28.5.4.Fill List To Another List
28.5.5.Fill Calendar Object To List
28.5.6.Properties Setting: Date
28.5.7.Property Setting Byte Array
28.5.8.Property Setting Boolean
28.5.9.Property Setting: BigDecimal
28.5.10.Property Setting Properties
28.5.11.Property Setting Integer
28.5.12.Property Setting File
28.5.13.Property Setting Class type
28.5.14.Property Setting Stream From URL
28.5.15.Property Setting: URL
28.5.16.Property Setting String Array
28.5.17.Fill Value To List
28.5.18.Create List, Map In Context
28.5.19.Bean Injection: Map
28.5.20.Bean Injection: Collection Set
28.5.21.Bean Injection Collection Properties
28.5.22.Bean Injection: Collection Map
28.5.23.Bean Injection: Collection List
28.5.24.Load property File In Context