2017-10-13 12 views
0

を参照すると、同様のスタックオーバーフロートピック:JBoss EAP 7サーバー上のweb.xmlから<em>src/resources/settings.properties</em>ファイルに格納されているグローバル値にアクセスするために、Web.XMLのシステムプロパティを読み取る

public class ConfigurationWebFilter implements ServletContextListener { 
     protected static final Properties properties = new Properties(); 

    @Override 
    public void contextInitialized(final ServletContextEvent event){ 
     try { 
      try (InputStream stream = new FileInputStream("/settings.properties")) { 
       properties.load(stream); 
      } 

      for (String prop : properties.stringPropertyNames()) 
       { 
       if (System.getProperty(prop) == null) 
       { 
        System.setProperty(prop, properties.getProperty(prop)); 
       } 
       } 
     } catch (IOException ex) { 
      logger.error("Failed loading settings from configuration file for web.xml", ex); 
     } 
    } 

} 

は、その後、私はweb.xmlに応じてリスナーを追加しました:

<listener>  
    <listener-class> 
    com.product.util.ConfigurationWebFilter 
    </listener-class> 
    </listener> 

コードが正しく呼び出されると、私はシステム変数が正しく設定されますデバッグで確認できます。しかし、私のweb.xmlのプロパティは、置き換えられる/解釈されないようです。次のパラメータはまだでも、サーバーを再起動し、および/または再発行した後、$ {serverNameの}に評価されない:解決策は私のために働いていないので、この問題に関する

<filter> 
    <filter-name>CAS Authentication Filter</filter-name> 
    <filter-class>(...)</filter-class> 
    <init-param> 
    <param-name>serverName</param-name> 
    <param-value>${serverName}</param-value> 
    </init-param> 
</filter> 

他のすべてのトピックは役に立たないのでした。 web.xmlパラメータをプロパティファイルに格納された値で置き換えるにはどうすればよいですか?

+0

こんにちは騎士には、DocumentBuilderを使用してxmlを読み込み、javaから値を設定することができるJaxB、DocumentBuilders、JsoupなどのXMLを構文解析できる方法がたくさんあります。 – Pradeep

+0

https://www.mkyong.com/java/どのようにして-xml-file-in-java-dom-parser/ – Pradeep

+0

このリンクをたどってください – Pradeep

答えて

0

これで、Wildfly standalone.xmlで変数の置換に関連するパラメータをtrue(false)に設定する必要がありました。

+0

もっと正確に言えば、パラメータは ' true'です。 –

関連する問題