Home Tutorial Spring Spring3 Web SPEL-System Property


Share on Google+Share on Google+
SPEL-System Property
Posted on: April 8, 2011 at 12:00 AM
In this tutorial you will learn about SPEL System Property

Accessing System Property Using SpEL

Spring 3 provides powerful Expression Language which can be used to work with system properties. Lets take an example to demonstrate how SpEL is used to access system properties.

MyClass.java: The MyClass class contains property named "prop" which is of String type.

package spel.systemproperty;

public class MyClass
private String prop;

public void setProp(String prop) {
this.prop = prop;
public String getProp() {
return prop;

spring-beans.xml: We will see how to access values of system properties. Spring EL provides systemProperties attribute which provides access to the system properties available to the application which is same as calling same System.getProperties().

<beans xmlns="http://www.springframework.org/schema/beans"

<bean id="myClass" class="spel.systemproperty.MyClass">
<property name="prop" value="#{systemProperties.myProperty}"/>


AppMain.java: This class loads the context configuration file spring-beans-list.xml from the class path.

package spel.systemproperty;

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

import spel.systemproperty.MyClass;

public class AppMain{
public static void main( String[] args ){
System.setProperty("myProperty", "xyz");

ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"spel\\systemproperty\\spring-beans-list.xml"});
MyClass myObj = (MyClass)appContext.getBean("myClass");

System.out.println("System Property 'myProperty' Value: "+myObj.getProp());

The output of the above program will be as below:

System Property 'myProperty' Value: xyz

Download Code


Related Tags for SPEL-System Property:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 8, 2011

Recommend the tutorial

Advertisements Advertisements