0

I have following property in my application.properties file.

test.product.release.version=2003.1

test.product.release.year=#{'${test.product.release.version}'.split('[.]')[0]

When I use the property test.product.release.year in my spring controller using @Value annotation, it's giving me value as 2003, but when I get the value of it through AbstractEnvironment#getProperty I am getting value as

#{'${test.product.release.version}'.split('[.]')[0]

How can I get the value 2003 by using AbstractEnvironment?

  • Possible duplicate of [Using Expressions in Spring application.properties file](https://stackoverflow.com/questions/45704466/using-expressions-in-spring-application-properties-file) –  Jul 31 '19 at 13:20
  • Is this resolved? –  Aug 02 '19 at 18:04

1 Answers1

0

No you can not use SpEL within properties files.

Finally, while you can write a SpEL expression in @Value, such expressions are not processed from Application property files.

You can however use placeholders within properties files, eg:

app.name=MyApp
app.description=${app.name} is a Spring Boot application

For your use case, you should look at the profile-specific configuration mechanism.

Which allows you to load different config based on an environment profile.