1

Suppose I have an src/main/ressources/application.properties containing the following (exemplary) entry:

server.ssl.trust-store=/config/app.jks

and multiple application.properties for multiple enviroments

/config
|---/prod
|   |---/application.properties // overrides "server.ssl.trust-store"
|---/int
    |---/application.properties
/src
|---/main
    |---/resources
        |---/application.properties // contains entry "server.ssl.trust-store"

Both application.properties in /config directory inherits from the src/main/resources/application.properties. In /config/prod/application.properties we want to override the entry. This all works as expected.

Now, my question is: is it possible to inhibit the inheritance of properties? I tried overwriting it with an empty value, but that didn't worked and was differently interpreted as not setting it at all.

Note: For this particular case I know of the existence of server.ssl.enabled=false (source).

6
  • commenting-out (or removing or filtering) the property server.ssl.trust-store (in config/prod) isn't an option? May 23, 2022 at 12:20
  • Commenting out is not an option, because it is used in most of the other environments. Filtering how? May 24, 2022 at 7:31
  • if this config/ directory is copied to a production deployment, it could be perhaps filtered by a sed script to exclude some properties May 24, 2022 at 7:45
  • The problem is the copy of src/main/ressources/application.properties in midst of compiling, not the /config directory. May 24, 2022 at 7:50
  • but, if i understood correctly, you want to prevent a property from config to override a property from classpath properties (/src/main/resources) May 24, 2022 at 7:55

1 Answer 1

6
+50

You could create a new spring profile, for example, ssl, and add the ssl configurations there

# in application-ssl.properties
server.ssl.trust-store=/config/app.jks

You can then enable these configurations in your apps on demand by "importing" the ssl profile.

# in application-prod.properties
spring.profiles.include=ssl

You would leave out this statements where you wouldn't want to have that value present.

Another way is to directly configure conditional properties in the application.properties

# in common application.properties
spring.myproperty=44 # ... etc, normal app properties
---
spring.config.activate.on-profile=ssl # These configs apply to the ssl profile
server.ssl.trust-store=/config/app.jks
1
  • By now, this seems to be the best answer. They really closed the gate to modifying application.properties after starting the application. May 28, 2022 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.