Fill Properties : XML Bean Property « Spring « Java






Fill Properties

       
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="collectionsExample" class="CollectionsBean">
    


    <property name="theProperties">
      <props>
        <prop key="left">right</prop>
        <prop key="up">down</prop>
      </props>
    </property>

  </bean>
  
  <bean id="curDate" class="java.util.GregorianCalendar"/>
  
</beans>


File: Main.java

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

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");
    
    
    CollectionsBean example = (CollectionsBean) ctx.getBean("collectionsExample");
   System.out.println(example.getTheProperties());
  
  }
}
class CollectionsBean {
  
  private List theList;
  private Set theSet;
  private Map theMap;
  private Properties theProperties;
  
  public void setTheList(List theList) {
    this.theList = theList;
  }
  public List getTheList() {
    return theList;
  }
  
  public void setTheSet(Set theSet) {
    this.theSet = theSet;
  }
  public Set getTheSet() {
    return theSet;
  }
  
  public void setTheMap(Map theMap) {
    this.theMap = theMap;
  }
  public Map getTheMap() {
    return theMap;
  }
  
  public void setTheProperties(Properties theProperties) {
    this.theProperties = theProperties;
  }
  public Properties getTheProperties() {
    return theProperties;
  }
}




           
       








Spring-FillProperties.zip( 2,893 k)

Related examples in the same category

1.Property Setting: URL
2.PropertySetting: String Array
3.Property Setting: Stream From URL
4.Property Setting: Properties
5.Property Setting: Integer
6.Property Setting: File
7.Property Setting: Class type
8.Property Setting: Byte Array
9.Property Setting: Boolean
10.Property Setting: BigDecimal
11.Properties Setting: Date
12.Load property File In Context
13.lazy init
14.Fill Value To List
15.Fill Map
16.Fill Set
17.Fill List To Another List
18.Fill Calendar Object To List
19.Create List Map In Context
20.Bean Injection: Map
21.Bean Injection Collection: Set
22.Bean Injection: Collection Properties
23.Bean Injection Collection: Map
24.Bean Injection Collection: List