【问题标题】:How can I get profile specific pom properties in web.xml in Spring?如何在 Spring 的 web.xml 中获取配置文件特定的 pom 属性?
【发布时间】:2014-08-26 23:23:55
【问题描述】:

我在我的 spring 项目中使用了一项服务。我的 web.xml 中有以下代码:-

<init-param>
            <param-name>prerenderServiceUrl</param-name>
            <param-value>http://10.0.0.45:3000</param-value>
</init-param>

我的 pom.xml 中有 3 个配置文件:暂存、开发和生产:
我正在寻找在我的 web.xml 中获取 my.service.url> 的最佳做法:

<profile>
    ...
        <properties>
                ...
<my.service.url>http://10.0.0.45:300</my.service.url>
          ...
        </properties>
</profile>

【问题讨论】:

    标签: java maven spring-mvc pom.xml web.xml


    【解决方案1】:

    我觉得maven资源插件的过滤功能是你需要的:(http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html)

    也许您可以考虑将环境特定变量存储在目标环境中,而不是在构建脚本/属性中,并且您可以在启动期间从类路径中加载它。将您的环境设置与您的 pom.xml 紧密耦合会增加您在每次环境更改或添加新服务器时更新构建设置的额外工作。

    【讨论】:

      【解决方案2】:

      即使您可以使用配置文件,在这种情况下也不应该使用它们。这个想法是您可以一遍又一遍地分发相同的战争并且配置被拉入。阅读How to pass value to maven pom.xml at rum time from java file?了解所有选项。

      【讨论】:

        猜你喜欢
        • 2018-08-09
        • 2016-07-12
        • 2018-08-24
        • 2019-06-28
        • 1970-01-01
        • 2011-11-26
        • 1970-01-01
        • 2020-12-21
        • 1970-01-01
        相关资源
        最近更新 更多