首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-boot-maven-plugin -在随机端口启动JMX

spring-boot-maven-plugin -在随机端口启动JMX
EN

Stack Overflow用户
提问于 2021-01-19 10:03:04
回答 1查看 168关注 0票数 0

关于如何随机启动jmxPort的小问题,请使用spring-boot-maven-plugin。

目前,我正在使用spring-boot-maven-plugin运行集成测试,它需要jmxPort。

因此,我这样初始化它:

代码语言:javascript
复制
<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不工作。

请告诉我如何随机开始?

谢谢你

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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一起使用。

您的配置将如下所示:

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65784563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档