栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Maven Spring Boot插件:如何从另一个项目运行Spring Boot

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Maven Spring Boot插件:如何从另一个项目运行Spring Boot

我认为无法使用来对另一个模块进行集成测试

spring-boot-maven-plugin
,因为
start
目标似乎并未给您提供从本地存储库或Maven反应器解析应用程序的方法,而这可能正是您想要的。
project
您尝试使用的配置属性并非旨在以这种方式覆盖。只能使用插件目标文档中列出的属性来配置插件执行。

相反,我认为您至少有两种可能的方法:

  1. 使用其他插件来控制服务器;要么
  2. 直接通过代码中的测试运行服务器。

选项1

为此,我认为您需要一种在您想要运行的服务器工件中复制的方法,以及一些用于启动和停止它的更常规的方法,例如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>

选项2

只需在测试工件上声明对服务器工件的正常Maven依赖关系,然后

@SpringBootApplication
在进行钩子或其他操作之前在JUnit中运行服务器的类,例如

private static ConfigurableApplicationContext context;@BeforeClasspublic static void setUp() {    context = new SpringApplicationBuilder(SimpleServiceApplication.class).run();}@AfterClasspublic static void tearDown() {    if (context != null) {        context.close();    }}

这可能足以满足您的需求。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/615645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号