大佬教程收集整理的这篇文章主要介绍了Maven Spring Boot插件:如何从另一个项目运行Spring Boot,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我认为无法使用来对另一个模块进行集成测试spring-boot-maven-
plugin
,因为start
目标似乎并未给您提供从本地存储库或Maven反应器解析应用程序的方法,而这可能正是您想要的。project
您尝试使用的配置属性并非旨在以这种方式覆盖。只能使用插件目标文档中列出的属性来配置插件执行。
相反,我认为您至少有两种可能的方法:
为此,我认为您需要一种在您想要运行的服务器工件中复制的方法,以及一些用于启动和停止它的更常规的方法,例如cargo- maven2-plugin或process-exec-maven- plugin。
只需repackage
在服务器工件构建中配置目标:
<plugin>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-maven-plugin</artifactID>
<configuration>
<excludeDevtools>true</excludeDevtools>
</configuration>
<EXECUTIONS>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
然后,从集成测试模块中,您可以执行以下操作:
<plugin>
<artifactID>maven-dependency-plugin</artifactID>
<EXECUTIONS>
<execution>
<ID>copy-server-artifact</ID>
<goals>
<goal>copy</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupID>${project.groupID}</groupID>
<artifactID>SpringBoot2App</artifactID>
<version>${project.version}</version>
<classifIEr>jar</classifIEr>
<outputDirectory>${project.build.directory}</outputDirectory>
<destfilename>app.jar</destfilename>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</EXECUTIONS>
</plugin>
<plugin>
<groupID>com.bazaarvoice.maven.plugins</groupID>
<artifactID>process-exec-maven-plugin</artifactID>
<version>0.7</version>
<EXECUTIONS>
<execution>
<ID>start-server</ID>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<name>run-server</name>
<waitForInterrupt>false</waitForInterrupt>
<healthcheckUrl>http://localhost:8080</healthcheckUrl>
<arguments>
<argument>java</argument>
<argument>-jar</argument>
<argument>${project.build.directory}/app.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<ID>stop-server</ID>
<phase>post-integration-test</phase>
<goals>
<goal>stop-all</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
只需在测试工件上声明对服务器工件的正常Maven依赖关系,然后@SpringBootApplication
在进行钩子或其他操作之前在JUnit中运行服务器的类,例如
private static ConfigurableApplicationContext context;
@BeforeClass
public static voID setUp() {
context = new SpringApplicationBuilder(SimpleserviceApplication.class).run();
}
@AfterClass
public static voID tearDown() {
if (context != null) {
context.close();
}
}
这可能足以满足您的需求。
https://docs.spring.io/spring-boot/docs/current/maven-
plugin/usage.html
我有一个项目,有2个模块。
[Parent]
|-pom.xml
| [SpringBoot2App]
| |-pom.xml
| [test]
| |-pom.xml (start goal here!)
我想在另一个模块的单独项目中运行集成测试(Maven故障安全插件)。
在父模块的集成测试期间,可以配置spring boot maven插件来启动/停止子模块吗?
我尝试这样的事情没有成功
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.SimpleserviceApplication</mainClass>
<classesDirectory>../SpringBoot2App/target/classes</classesDirectory>
<folders>
<param>../SpringBoot2App/target/test-classes</param>
</folders>
</configuration>
<EXECUTIONS>
<execution>
<goals>
<goal>start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
</EXECUTIONS>
</plugin>
哪个不起作用。
在阅读插件的超类的源https://github.com/spring-projects/spring-boot/blob/master/spring-
boot-project/spring-boot之后,我还尝试添加“
project”参数 -工具/spring-boot-maven-
plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
<configuration>
<mainClass>com.SimpleserviceApplication</mainClass>
<project>${project.parent.collectedProjects[0]}</project>
</configuration>
如调试所示,这是指正确的项目,但也不起作用。
请不要对[0]进行评论,我知道[0]并不干净,并且是需要直接了解父pom模块排序的耦合。
我在org / springframework / boot /
SpringApplication上收到java.lang.NoClassDefFoundError
我将starter-web项目添加到测试pom.xml,结果相同
以上是大佬教程为你收集整理的Maven Spring Boot插件:如何从另一个项目运行Spring Boot全部内容,希望文章能够帮你解决Maven Spring Boot插件:如何从另一个项目运行Spring Boot所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。