7

tomcat のさまざまな war ファイルにさまざまな環境変数を設定する方法はありますか? 私はサードパーティの戦争を使用しており、同じ戦争の複数の展開が必要ですが、環境変数が異なります (したがって、異なる構成が読み込まれます)。

4

2 に答える 2

1

わかりました、完全にクレイジーなハックのアイデア:

各アプリ インスタンスに PropertyPlayHolderConfigurer を実装 (または Tomcat の web.xml を使用) し、System.properties() と同じ名前のプロパティを読み込みます。

次に、両方のプロパティ セットを含むデリゲート Properties クラスを作成します。それで

Properties props = new DelegatingProperties(app1Props,app2Props)
System.setProperties(delegate);

public class DelegatingProperties extends Properties {

   private Properties app1Props;
   private Properties app2Props;

   public DelegatingProperties(Properties app1Props, Properties app2Props) {
        this.app1Props = app1Props;
        this.app2Props = app2Props;   
   }

   public String getProperty(String prop) {
       // begin crazy science
       String caller = new Throwable().getStackTrace()[0].getClassName();
       // this is where you get creative.
       // Do the System.setProperties() above so you can intercept calls to  
       //getProperty()
       // and find out the FQCN of the library class(es) that need these variable 
       // (use your debugger).
       // then implement the logic here to decide which of the 2 property sets you have
       // you will query to get the correct results     
   }
}

これらは、私たちが話しているSYSTEMプロパティであり、システム全体に適用されることを意図しています。あなたのライブラリは、おそらく 1-app-1-jvm のときに開発されたものです (または、開発者が遅れている可能性もあります)。

少なくとも創造性のための小道具を手に入れることはできますか? :)

于 2013-06-06T17:25:57.653 に答える