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" />
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.
Using ExpressionParser. ExpressionParser is responsible for parsing expression strings. In this example, SpEL parser will simply evaluate the string 'Any String' as an expression.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With