2014-10-01 105 views
6

我有一個由多個maven戰爭項目組成的應用程序。Spring Boot中多重應用程序的集成測試

我有另一個maven項目,它使用org.springframework.web.client.RestTemplate調用對手動啓動的tomcat部署的多戰爭應用程序運行JUnit集成測試。

但是,我希望我的集成測試項目能夠在運行我的測試之前真正啓動我的多重戰爭應用程序(在整個套件期間一次)...在spring-boot中!

從我的集成測試項目中,我希望能夠將所有戰爭項目作爲spring-boot應用程序一起運行,每個應用程序都有自己的contextPaths(例如localhost:8080/a用於項目'a',localhost :項目'b'的8080/b等),並且不需要改變原始的戰爭項目(那些(但還沒有)彈簧啓動)。如果我無法讓這些項目在我的集成測試項目中運行,而無需更改它們,那麼我至少要儘量減少在打包的war文件中使用spring-boot依賴項和配置......儘可能多。

我能夠讓我的集成測試項目依賴於一個單一的戰爭項目,啓動它並對它進行測試......但我沒有成功獲取兩個戰爭項目在spring-boot下一起運行在不同的contextPaths下。

歡迎任何建議!

這裏有一些我一直在使用共同把這個資源:

+2

我困惑。這聽起來像你試圖運行的戰爭沒有使用Spring Boot。假設這是正確的,你爲什麼試圖用Spring Boot來運行它們?我可能誤解了。你可以擴展一下你想要達到的目標嗎?爲什麼你認爲Spring Boot會幫助你實現目標? – 2014-10-02 08:04:45

+0

好問題@AndyWilkinson。你是對的。戰爭不使用彈簧靴,我不打算這樣做。他們將部署在WebLogic中進行生產。但是,我想以完全部署的應用程序(本地和Jenkins CI版本)運行集成測試,這樣我就不必手動啓動tomcat中的所有戰爭。而不是像'mvn測試'。我認爲春季引導可能是一個很好的候選人。這有幫助嗎? – sdoxsee 2014-10-02 13:13:54

+3

我不認爲Spring Boot是這項工作的正確工具。你不能使用Tomcat的Maven插件並將其配置爲部署多個Web應用程序嗎?這樣的事情:http://stackoverflow.com/a/13193937/1384297 – 2014-10-02 14:19:54

回答

6

根據Andy的建議,我使用了Tomcat7 Maven Plugin,它工作得很好。 Jetty Maven插件是另一種選擇(並且更好地記錄了IMO),儘管我無法找到避免必須爲我的WAR文件提供「路徑」的方法。 Tomcat7 Maven插件讓我從我的本地.m2版本庫加載我的WAR。我還要說,以下鏈接是有益的,以及...

這裏是我的集成測試項目POM的一部分......

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.17</version> 
      <configuration> 
       <skipTests>true</skipTests> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <version>2.17</version> 
      <configuration> 
       <includes> 
        <include>**/*Test*</include> 
       </includes> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <path>/</path> 
       <webapps> 
        <webapp> 
         <groupId>com.mycompany</groupId> 
         <artifactId>app1</artifactId> 
         <version>${project.version}</version> 
         <type>war</type> 
         <asWebapp>true</asWebapp> 
        </webapp> 
        <webapp> 
         <groupId>com.mycompany</groupId> 
         <artifactId>app2</artifactId> 
         <version>${project.version}</version> 
         <type>war</type> 
         <asWebapp>true</asWebapp> 
        </webapp> 
       </webapps> 
      </configuration> 
      <executions> 
       <execution> 
        <id>start-tomcat</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>run-war</goal> 
        </goals> 
        <configuration> 
         <fork>true</fork> 
        </configuration> 
       </execution> 
       <execution> 
        <id>stop-tomcat</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>shutdown</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

有沒有辦法阻止maven或tomcat插件加載webapps,如果我運行mvn clean install -DskipTests? – 2016-03-17 17:48:06

相關問題