Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is SpEL supported in import statements?

I would like to import different resource files based on some condition. Is this possible?

These don't work:

<import resource="#{ systemProperties['foo'] }.xml" /> 

<import resource="#{ T(my.testpkg).getValue() }.xml" /> 
like image 249
Darth Ninja Avatar asked Nov 02 '12 17:11

Darth Ninja


People also ask

Is SpEL a programming language?

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.

Which of the following can be used to fetch the value of a SpEL expression @SpEL?

Using ExpressionParser. ExpressionParser is responsible for parsing expression strings. In this example, SpEL parser will simply evaluate the string 'Any String' as an expression.


1 Answers

SpEL is supported, but Spring resolves the import statement very early on.

When spring is resolving import statements, property placeholders have not yet been resolved.

For example:

Define the following properties:

import.fileName=${blah}
blah=properties.props

We can then use the 'import.fileName' property as a parameter to the import

<import resource="${import.fileName}" />

This resolves to:

<import resource="${blah}" />

And presumably the resource '${blah}' does not exist.

That being said, you can use properties to resolve import file names.

like image 170
Kyle Avatar answered Oct 04 '22 20:10

Kyle