Share on Google+Share on Google+

SPEL-System Property

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. 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=""

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

</beans> This class loads the context configuration file spring-beans-list.xml from the class path.

package spel.systemproperty;

import org.springframework.context.ApplicationContext;

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



Posted on: April 8, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.