关于如何随机启动jmxPort的小问题,请使用spring-boot-maven-plugin。
目前,我正在使用spring-boot-maven-plugin运行集成测试,它需要jmxPort。
因此,我这样初始化它:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<wait>1000</wait>
<maxAttempts>180</maxAttempts>
<jmxPort>0</jmxPort>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>integration</SPRING_PROFILES_ACTIVE>
</environmentVariables>
<jvmArguments>
-Dspring.application.admin.enabled=true
</jvmArguments>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>但是,端口0不工作。
请告诉我如何随机开始?
谢谢你
发布于 2021-01-19 10:22:04
例如,您可以使用org.codehaus.mojo.build-helper-maven-plugin
https://www.mojohaus.org/build-helper-maven-plugin/
您将在您的插件配置中再添加一个步骤。此步骤将生成具有随机端口号的变量,然后可以将其与spring-boot-maven-plugin一起使用。
您的配置将如下所示:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>random.jmx.port</portName>
</portNames>
<randomPort>true</randomPort>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<wait>1000</wait>
<maxAttempts>180</maxAttempts>
<jmxPort>${random.jmx.port}</jmxPort>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>integration</SPRING_PROFILES_ACTIVE>
</environmentVariables>
<jvmArguments>
-Dspring.application.admin.enabled=true
</jvmArguments>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>https://stackoverflow.com/questions/65784563
复制相似问题