我有一个多模块的maven spring-booot项目。其中一个子模块是存根(一个spring boot应用程序),我希望在 myRealApp的集成测试期间启动并停止。
Parent Pom
|
|----myRealApp module(spring boot app)
|----stub-of-some-remote-rest-api module(This is also a spring-boot app)这是模块myRealApp中的pom文件的样子。它也有所有的集成测试。它试图在集成测试前阶段启动存根模块。但是当我在子模块目录中运行maven goal时,我得到了这个错误:
mvn integration-tests -X错误:无法找到或加载主类io.swagger.MyStub
org.apache.maven.lifecycle.LifecycleExecutionException:无法对项目执行目标org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:run (启动-启动):无法执行java
在调试模式下,我可以看到工作目录设置正确。
myRealApp的Pom:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
<executions>
<execution>
<configuration>
<workingDirectory>${project.parent.basedir}/module-of-my-stub/src/main/java</workingDirectory>
<mainClass>io.swagger.MyStub</mainClass>
</configuration>
<id>start-boot</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-boot</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>也许我不被允许在单独的执行中设置workingDirectory,或者引用其他模块?
存根在那里就像我的应用程序所依赖的远程rest服务,我在开发过程中使用了它,因为实际远程服务的测试环境并不可靠,而且有一半的时间是关闭的。所以决定也在集成测试中使用它。
发布于 2018-08-23 02:45:30
为了整合针对这个问题的一些评论,这些评论基本上遵循了this other answer中的建议。
关键是根据spring-boot-maven-plugin:run目标将classesDirectory设置为指向另一个项目下的target\classes目录。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
<executions>
<execution>
<id>start-stub</id>
<configuration>
<arguments>
<argument>--server.port=8090</argument>
</arguments>
<mainClass>io.swagger.Stub</mainClass>
<classesDirectory>../my-stub/target/classes</classesDirectory>
</configuration>
<goals>
<goal>start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>发布于 2018-08-22 03:49:25
spring-boot:run只适用于打包了springboot应用程序的项目。实现此功能的最佳选择:您将需要使用exec-maven-plugin:exec,并确保将async设置为true。看看https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html,看看应该如何配置这个插件。
https://stackoverflow.com/questions/51874095
复制相似问题