Search code examples
javaspringspring-bootjndi

Spring-Boot > Setting application.properties using JNDI


According to this github issue, I can specify the location of an application.properties file. e.g.

JNDI Environment Resource:

java:comp/env/spring.config.location = /some/path/application.properties

What I'd like to know is:

Can I use a JNDI binding to directly configure an individual application.properties property value in my Spring Boot application?

I've tried the following JNDI vars (to no avail):

JNDI Environment Resource:

java:comp/env/my.env.myCustomStringField = foobar
java:comp/env/my.env.my-custom-string-field = foobar

Spring Reference:

If you are running in a container then JNDI properties (in java:comp/env) or servlet context initialization parameters can be used instead of, or as well as, environment variables or system properties.

I'm currently using the following workaround.


Solution

  • Not sure what I was thinking, you can use JNDI to set the location of the application.properties file, and/orr override any application variables.

    e.g.

    spring.config.location = file:/some/location/properties/
    my.env.myCustomStringField = foobar
    

    Don't bother with the java:comp/env/, Spring shields you from it.