Over a million developers have joined DZone.

Spring Expression Language (SpEL) Predefined Variables

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

Spring 3.0 introduced Spring Expression Language (SpEL). There are two variables that you have available “systemProperties” and “systemEnvironment“. SpEL allows us to access information from our beans and system beans information at runtime (late binding).

These can be applied to bean fields as defaults using the JSR-303 @Value annotation on a field or in XML with the <bean ... value="" /> options.

  • systemProperties – a java.util.Properties object retrieving properties from the runtime environment
  • systemEnvironment – a java.util.Properties object retrieving environment specific properties from the runtime environment

We can access specific elements from the Properties object with the syntax:

  • systemProperties['property.name']
  • systemEnvironment['property.name']

public class MyEnvironment {

@Value("#{ systemProperties['user.language'] }")
private String varOne;

@Value("#{ systemProperties }")
private java.util.Properties systemProperties;

@Value("#{ systemEnvironment }")
private java.util.Properties systemEnvironment;

@Override
public String toString() {
return "\n\n********************** MyEnvironment: [\n\tvarOne="
+ varOne + ", \n\tsystemProperties=" + systemProperties
+ ", \n\tsystemEnvironment=" + systemEnvironment + "]";
}
}

Register the “MyEnvironment” bean in your Spring context and create a JUnit test to display the variables.

 

From http://gordondickens.com/wordpress/2011/05/12/spring-expression-language-spel-predefined-variables/

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}