DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building a CRUD Application With Spring and SimpleJdbcMapper
  • How to Marry MDC With Spring Integration
  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux

Trending

  • Manual Investigation: The Hidden Bottleneck in Incident Response
  • Understanding MCP Architecture: LLM + API vs Model Context Protocol
  • Hallucination Has Real Consequences — Lessons From Building AI Systems
  • The Prompt Isn't Hiding Inside the Image
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Expression Language (SpEL) Predefined Variables

Spring Expression Language (SpEL) Predefined Variables

By 
Gordon Dickens user avatar
Gordon Dickens
·
May. 16, 11 · Interview
Likes (0)
Comment
Save
Tweet
Share
24.2K Views

Join the DZone community and get the full member experience.

Join For Free

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/

Spring Framework

Opinions expressed by DZone contributors are their own.

Related

  • Building a CRUD Application With Spring and SimpleJdbcMapper
  • How to Marry MDC With Spring Integration
  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook