【问题标题】:Integration testing of multi-war application in Spring BootSpring Boot中多war应用的集成测试
【发布时间】:2014-11-26 18:52:14
【问题描述】:

我有一个由多个 maven war 项目组成的应用程序。

我有另一个 maven 项目,它使用 org.springframework.web.client.RestTemplate 调用针对手动启动的 tomcat 部署的多战争应用程序运行 JUnit 集成测试。

但是,我希望我的集成测试项目在运行我的测试之前实际启动我的多战争应用程序(在整个套件期间一次)...在 spring-boot 中!

从我的集成测试项目中,我希望能够将所有 war 项目作为一个 spring-boot 应用程序一起运行,每个项目都有自己的 contextPaths(例如项目 'a' 的 localhost:8080/a,localhost: 8080/b 用于项目 'b' 等),并且不更改原始战争项目(还没有(还)spring-boot 感知)。如果我不能在不更改它们的情况下使这些项目在 spring-boot 中从我的集成测试项目中运行,那么我至少希望在打包的 war 文件中尽量减少 spring-boot 依赖项和配置的使用......尽可能.

我能够让我的集成测试项目依赖于一个单一的战争项目,启动它并针对它运行测试......但我没有成功让两个战争项目在 spring-boot 中在不同的 contextPaths 下一起运行。

欢迎提出任何建议!

以下是我一直在使用的一些资源:

【问题讨论】:

  • 我很困惑。听起来您尝试进行的战争没有使用 Spring Boot。假设这是正确的,您为什么要尝试使用 Spring Boot 来运行它们?我可能误会了。您能否详细介绍一下您想要实现的目标以及为什么您认为 Spring Boot 会帮助您实现它?
  • 好问题@AndyWilkinson。你是对的。战争没有使用弹簧靴,我不打算这样做。它们将部署在 WebLogic 中用于生产。但是,我想对完全部署的应用程序(本地和 Jenkins CI 构建)运行集成测试,这样我就不必先手动启动 tomcat 中的所有战争......而像' mvn 测试'。我认为弹簧靴可能是一个很好的选择。这有帮助吗?
  • 我不认为 Spring Boot 是适合这项工作的工具。不能用 Tomcat 的 maven 插件,配置它来部署多个 web 应用吗?像这样的东西:stackoverflow.com/a/13193937/1384297

标签: java spring maven junit spring-boot


【解决方案1】:

根据 Andy 的建议,我使用了 Tomcat7 Maven 插件,它运行良好。 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>

【讨论】:

  • 如果我运行 mvn clean install -DskipTests,有没有办法阻止 maven 或 tomcat 插件加载 webapps?
猜你喜欢
  • 2020-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-20
  • 2020-04-24
  • 2017-10-27
  • 1970-01-01
  • 2016-02-25
相关资源
最近更新 更多