tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > Expression Language > XML Configuration

XML Configuration 

The Spring Expression Language (SpEL) is a simple and powerful expression language which helps to query and manipulate objects at runtime. We can use Spring Expression Language to set a constructor argument or property value.

File Name  :  
/SpringCore001/conf/spel/basic.xml 

File Name  :  
com/bethecoder/tutorials/spring3/basic/SimpleBean.java 
   
package com.bethecoder.tutorials.spring3.basic;

public class SimpleBean {

  private String simpleProp;

  public String getSimpleProp() {
    return simpleProp;
  }

  public void setSimpleProp(String simpleProp) {
    this.simpleProp = simpleProp;
  }
  
}
   

File Name  :  
com/bethecoder/tutorials/spring3/basic/ComplexBean.java 
   
package com.bethecoder.tutorials.spring3.basic;

public class ComplexBean {

  private java.util.Properties simpleProps;
  private java.util.List simpleList;
  private java.util.Map simpleMap;
  private java.util.Set simpleSet;
  
  public java.util.Properties getSimpleProps() {
    return simpleProps;
  }
  
  public void setSimpleProps(java.util.Properties simpleProps) {
    this.simpleProps = simpleProps;
  }
  
  public java.util.List getSimpleList() {
    return simpleList;
  }
  
  public void setSimpleList(java.util.List simpleList) {
    this.simpleList = simpleList;
  }
  
  public java.util.Map getSimpleMap() {
    return simpleMap;
  }
  
  public void setSimpleMap(java.util.Map simpleMap) {
    this.simpleMap = simpleMap;
  }
  
  public java.util.Set getSimpleSet() {
    return simpleSet;
  }
  
  public void setSimpleSet(java.util.Set simpleSet) {
    this.simpleSet = simpleSet;
  }
}
   

File Name  :  
com/bethecoder/tutorials/spring3/tests/spel/XMLConfigurationTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.spring3.tests.spel;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.bethecoder.tutorials.spring3.basic.ComplexBean;
import com.bethecoder.tutorials.spring3.basic.SimpleBean;

public class XMLConfigurationTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    ApplicationContext factory = new ClassPathXmlApplicationContext("basic.xml");
    
    SimpleBean rand = (SimpleBeanfactory.getBean("rand");
    System.out.println("Random Number : " + rand.getSimpleProp());

    ComplexBean lists = (ComplexBeanfactory.getBean("lists");
    System.out.println("String list : " + lists.getSimpleList());
    
    SimpleBean info = (SimpleBeanfactory.getBean("info");
    System.out.println("Info : " + info.getSimpleProp());
  }

}
   

It gives the following output,
Random Number : 1376.2272749811557
String list : [one, two, three, four]
Info : The value of 2 power 3 is 8



 
  


  
bl  br