【问题标题】:Is there a way to resolve system properties in a web.xml file?有没有办法在 web.xml 文件中解析系统属性?
【发布时间】:2009-03-26 16:41:34
【问题描述】:

我在 JBOSS 的 run.conf 中添加了一个系统属性,如下所示:

JAVA_OPTS="$JAVA_OPTS -Dfoo=bar"

现在我的问题是,是否有办法以如下方式解决 web.xml 文件中的此属性:

...
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    classpath:applicationContext-common.xml
    classpath:conf/${foo}/applicationContext-local.xml
  </param-value>
</context-param>
...

【问题讨论】:

    标签: java servlets jboss web.xml


    【解决方案1】:

    你必须将standalone.xml中的spec-descriptor-property-replacement设置为true

        <subsystem xmlns="urn:jboss:domain:ee:1.2">
            <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
            <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
        </subsystem>
    

    【讨论】:

      【解决方案2】:

      由于 JBoss 内部使用 tomcat web-container,它应该像您的示例一样工作 (${foo}/applicationContext-local.xml)。 JBoss的案例我没试过,但是我们在Tomcat中一直使用这种技术。

      【讨论】:

        【解决方案3】:

        web.xml 应仅适用于单个 Web 应用程序。它不应该有全局配置。所以不行。无论如何,当服务器和您的 web 应用程序加载完毕时,开始播放命令行参数已经太晚了。

        【讨论】:

          【解决方案4】:

          我不知道任何可能性。但在我看来,这应该在应用程序中实现。为什么要增加间接性?通常,您可以从应用程序(app > web.xml)中访问 web.xml 的内容。为什么这样做:app > web.xml > 环境变量?

          【讨论】:

          • 我知道,这只是我研究的一种可能的选择。如果我可以在我的 web.xml 文件中解决它,那将很容易,无需触及应用程序配置的每个文件。
          • 如果你的系统设计不错,你不应该经常碰它。您可以在静态方法后面隐藏“实现”,这意味着获取属性。你封装了你得到它的方式。对于两种解决方案,您调用它的次数应该相等。
          猜你喜欢
          • 1970-01-01
          • 2010-09-07
          • 2012-07-04
          • 2012-10-28
          • 1970-01-01
          • 1970-01-01
          • 2018-03-25
          • 1970-01-01
          • 2023-02-03
          相关资源
          最近更新 更多