Spring Boot中多WAR应用的集成测试

7
我有一个由多个maven war项目组成的应用程序。
我有另一个maven项目,使用org.springframework.web.client.RestTemplate调用手动启动的tomcat部署的多个war应用程序来运行JUnit集成测试。
然而,我希望我的集成测试项目实际上在spring-boot中启动我的多个war应用程序(整个套件的持续时间内仅启动一次),并为每个应用程序提供自己的contextPaths(例如,localhost:8080 / a表示项目“a”,localhost:8080 / b表示项目“b”等),而不更改原始的war项目(尚未意识到spring-boot)。如果我无法在不更改它们的情况下使这些项目在我的集成测试项目中以spring-boot运行,则至少要尽可能地减少打包的war文件中spring-boot依赖项和配置的使用。
我能够让我的集成测试项目依赖于单个war项目,启动它并对其运行测试……但是我无法使两个war项目在spring-boot下以单独的contextPaths一起运行。
欢迎任何建议!
以下是我用来组合这些资源的一些资源:

2
我有点困惑。听起来你尝试运行的系统不是使用Spring Boot的。如果我的理解正确,那么你为什么要尝试使用Spring Boot去运行它们呢?我可能误解了情况。你可以详细说明一下你想要实现什么以及为什么认为Spring Boot会帮助你实现它吗? - Andy Wilkinson
很好的问题@AndyWilkinson。你是正确的。这些war包没有使用spring boot,我也不打算这样做。它们将在WebLogic中部署用于生产。然而,我想以这样一种方式运行集成测试,即我不必首先手动启动所有的war包在tomcat中...而是像“mvn test”这样的东西。我认为spring boot可能是一个很好的选择。这有帮助吗? - sdoxsee
3
我认为Spring Boot不是合适的工具。你能否使用Tomcat的maven插件,并配置它来部署多个Web应用程序?类似于这样:https://dev59.com/Nmct5IYBdhLWcg3wnurg#13193937 - Andy Wilkinson
1个回答

6
根据Andy的建议,我选择了Tomcat7 Maven插件,它运行得很好。 Jetty Maven插件是另一个选项(在我看来更好地记录了),尽管我找不到避免提供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>

有没有办法防止Maven或Tomcat插件在运行mvn clean install -DskipTests时加载Web应用程序? - Michael K.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接