Spring-启动 > 使用 JNDI 设置 application.properties

Spring-Boot > Setting application.properties using JNDI

根据这个github issue,我可以指定一个application.properties文件的位置。例如

JNDI 环境资源:

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

我想知道的是:

我可以使用 JNDI 绑定直接在我的 Spring 引导应用程序中配置单独的 application.properties 属性 值吗?

我尝试了以下 JNDI 变量(无济于事):

JNDI 环境资源:

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.

我目前正在使用 the following workaround

不确定我在想什么,您可以使用 JNDI 设置 application.properties 文件的位置,and/orr 覆盖任何应用程序变量。

例如

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

不用担心 java:comp/env/,Spring 会屏蔽你。