Java spring boot maven插件-在随机端口启动JMX

Java spring boot maven插件-在随机端口启动JMX,java,spring-boot,maven,Java,Spring Boot,Maven,关于如何使用SpringBootMaven插件随机启动jmxPort的小问题 目前,我正在使用SpringBootMaven插件运行集成测试,它需要jmxPort 因此,我以这种方式初始化它: <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-mave

关于如何使用SpringBootMaven插件随机启动jmxPort的小问题

目前,我正在使用SpringBootMaven插件运行集成测试,它需要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>

org.springframework.boot
springbootmaven插件
1000
180
0
整合
-Dspring.application.admin.enabled=true
预集成测试
开始
整合后测试
停止
但是,端口0不工作

请问如何随机启动


谢谢

您可以使用例如
org.codehaus.mojo.buildhelpermaven插件

您将在插件配置中再添加一个步骤。此步骤将生成具有随机端口号的变量,该变量可与
spring boot maven插件一起使用

您的配置将类似于此:

<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>

org.codehaus.mojo
构建助手maven插件
3.2.0
预留网络端口
预留网络端口
过程资源
random.jmx.port
真的
org.springframework.boot
springbootmaven插件
1000
180
${random.jmx.port}
整合
-Dspring.application.admin.enabled=true
预集成测试
开始
整合后测试
停止
尽管报告了“无法解析符号'random.jmx.port'”,但这确实有效,非常感谢