fastcodejava
fastcodejava

Reputation: 41087

Refer other properties in Spring expression language

I have a field as shown below which works

@Value("#{T(java.util.regex.Pattern).compile('[0-9]+')}")
private Pattern myPattern;

But if I change it to

@Value("#{T(java.util.regex.Pattern).compile(${myProp})}")
private Pattern myPattern;

it does not work. Is there a way to refer properties inside Spring expression?

Upvotes: 2

Views: 653

Answers (1)

Ralph
Ralph

Reputation: 120771

I would guess that the 's are the problem. I would expect that SpEL handle '${myProp}' as a string but not as a property.

Therefore I would try to remove the 's

See my last comment

I have had a look at my code and found this:

@Value("#{new java.text.SimpleDateFormat('yyyy-MM-dd').parse('${showAfterDate}')}")

-- So '${myProp}' should work

Upvotes: 2

Related Questions