Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of Spring EL Variables?

Spring EL supports a some predefined variables

  • {#systemProperties. ... }
  • {#systemEnvironment. ... }
  • {#request. ...}
  • {#session. ...}

The first two once are documented in the Spring Reference: chapter 6. Spring Expression Language (SpEL). The two others are not mentioned in the Spring Reference (or I did not found them.) (I found them in this slides, as well as its usage in spring social and this question).

So my question is: is there a more or less complete list of predefined spring-el variables?

I guess that some of this predefined variables are not defined by spring core itself, but by "activating" of some modules like spring-mvc. So I am interested in the the variables that are available in a more or less common spring + jpa + mvc + security application.

like image 384
Ralph Avatar asked Oct 25 '11 07:10

Ralph


People also ask

What makes SpEL more powerful than el?

The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. The language syntax is similar to Unified EL but offers additional features, most notably method invocation and basic string templating functionality.

What are the features of SpEL?

SpEL supports a wide range of features, such as calling methods, accessing properties, and calling constructors. As an example of method invocation, we call the 'concat' method on the string literal. ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.

Which kind of expression Cannot be compiled by Spring framework?

0. I know in Spring 4.1 optimizations were added to allow compilation of SpEL expressions. it says currently only these are not supported: expressions involving assignment.


2 Answers

I also notice that environment resolves to the current org.springframework.core.env.Environment instance. I am not sure this is a documented feature, but I was looking for a concise way to do the following in my @Configuration class:

@Value("#{environment.acceptsProfiles('test')}")
private boolean test;

Which then allows me to switch off this value in further bean defintions.

I have submitted the following JIRA to address this issue:

https://jira.springsource.org/browse/SPR-9037

like image 55
btiernay Avatar answered Nov 05 '22 12:11

btiernay


I can not answer your root question but I may give you a hint.

There are some predefined beans registered at start up of your application context but which depends on the context type you are using.

Commonly, systemProperties and systemEnvironment are present. Loading Spring within a web application, you will also get servletContext, contextParameters and contextAttributes. I assume, request and session are related to a web application context as well.

I discovered this during debugging of my application which uses Spring 3.0.6RELEASE. A good starting point is SpringBeanELResolver.getValue() method.

like image 44
micfra Avatar answered Nov 05 '22 14:11

micfra