如何防止应用程序。Properties属性继承

发布于 2025-01-30 14:13:43 字数 974 浏览 4 评论 0 原文

假设我有一个 src/main/ressources/application.properties 包含以下(示例性)条目:

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

和多个application.properties for多个环境

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

application.properties。目录从src/main/resources/application.properties继承。在/config/prod/application.properties中,我们要覆盖条目。这一切都按预期工作。

现在,我的问题是:是否有可能抑制财产的继承? 我尝试用空价值覆盖它,但这没有起作用,并且被不同的解释为完全没有设置。

注意:对于这种特殊情况,我知道 server.ssl.enabled = false source )。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2025-02-06 14:13:43

您可以创建一个新的Spring配置文件,例如 ssl ,并在此处添加SSL配置,

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

然后可以通过“导入” SSL配置文件来按需在应用中启用这些配置。

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

您会忽略此陈述,而您不想拥有该价值。

另一种方法是在 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文