简体   繁体   English

有没有办法解析web.xml文件中的系统属性?

[英]Is there a way to resolve system properties in a web.xml file?

I added a system property in my run.conf of my JBOSS like this: 我在我的JBOSS的run.conf中添加了一个系统属性,如下所示:

JAVA_OPTS="$JAVA_OPTS -Dfoo=bar"

Now my question is, if there is a way to resolve this property in a web.xml file in a way something like this: 现在我的问题是,如果有办法在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>
...

You have to set spec-descriptor-property-replacement in standalone.xml to true 您必须将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>

Since JBoss internally uses the tomcat web-container, it should work like your example (${foo}/applicationContext-local.xml). 由于JBoss内部使用tomcat web容器,因此它应该像你的示例一样工作($ {foo} /applicationContext-local.xml)。 I haven't tried the JBoss case, but we use this technique all the time in Tomcat. 我没有尝试过JBoss案例,但我们一直在Tomcat中使用这种技术。

web.xml should apply to a single web application only. web.xml应仅适用于单个Web应用程序。 It should not have global configuration. 它不应该具有全局配置。 So no. 所以不行。 In any case, by the time the server and your webapp has loaded, it's way to late to start playing command line arguments. 在任何情况下,当服务器和您的webapp加载时,开始播放命令行参数是迟到的。

I don't know any possibility. 我不知道有任何可能性。 But in my opinion this should be implemented in the application. 但在我看来,这应该在应用程序中实现。 Why you wanna increase the indirection? 为什么你想增加间接? Normaly you access the contents of the web.xml from within you application ( app > web.xml). 通常,您可以从应用程序(app> web.xml)中访问web.xml的内容。 Why do this: app > web.xml > environment variable? 为什么这样做:app> web.xml>环境变量?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM