2011-11-22 79 views
5

我想設置我的項目根據環境使用不同的虛擬主機名稱。jboss-web.xml可以訪問屬性嗎?

我知道我可以在每個目錄中創建一個帶有單獨jboss-web.xml文件的目錄。但我最近把這個項目移到了maven,並想利用這些配置文件。我已經設置了數據庫,因此它們可以通過使用過濾器的配置文件進行不同的配置。

的jboss-web.xml中:

<jboss-web> 
    <context-root>/</context-root> 
    <virtual-host>${jbossweb.virtualhost}</virtual-host> 
</jboss-web> 

環境特定屬性文件中有一個條目:

jbossweb.virtualhost=hostname.domain.com 

的POM文件生成部分有這個定義

<filters> 
     <filter>src/main/filters/filter-${env}.properties</filter> 
    </filters> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
     <resource> 
      <directory>src/main/webapp/WEB-INF</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 

剛爲了更好的衡量,配置文件部分具有以下配置:

<profile> 
    <id>dev</id> 
    <properties> 
     <env>dev</env> 
    </properties> 
    </profile> 

我甚至不確定自己想做什麼是可能的。當我嘗試它時,Jboss-web.xml在虛擬主機位置具有變量名稱,而不是值。

我吠叫錯了樹嗎?

感謝,

埃裏克

+0

它_looks_就像你擁有所有的東西一樣。另一個略有不同的方法是在配置文件定義中包含'jbossweb.virtualhost'的值。 –

回答

10

其實,我發現了一個辦法做到這一點:

了JBoss-web.xml中現在看起來是這樣的:

<jboss-web> 
    <context-root>${jbossweb.contextroot}</context-root> 
    <virtual-host>${jbossweb.virtualhost}</virtual-host> 
</jboss-web> 

的屬性文件如下所示:

jbossweb.virtualhost=hostname 
jbossweb.contextroot=/ 

然後POM的部分看起來像這樣的Maven的戰爭插件配置:

   <webResources> 
        <resource> 
         <directory>src/main/webapp/WEB-INF</directory> 
         <filtering>true</filtering> 
         <include>jboss-web.xml</include> 
         <targetPath>/WEB-INF</targetPath> 
        </resource> 
       </webResources> 

而且過濾器上面的插件部分定義,但構建部分中,如下所示:

<filters> 
     <filter>src/main/filters/filter-${env}.properties</filter> 
    </filters> 
+2

webResources部分足以使用jboss-web.xml上的maven屬性進行過濾。 – Donatello

+0

我知道這是在幾年前回答的,所以版本可能不同;但是我可以通過從jboss-web.xml中除去context-root元素並從build.Application.properties文件中獲取server.context-path,從而在Spring Boot項目中使用它。 –