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

拍拍拍

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

目前,我正在使用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不起作用。

请如何随机启动?

谢谢

监控方式

您可以使用例如 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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在使用spring-boot-maven-plugin创建的嵌套可执行jar中启动主类

无法跳过spring-boot-maven-plugin的重新打包目标

spring-boot-maven-plugin 重新打包执行默认失败

Spring-Boot-Maven-Plugin 问题“无法转移”

“ spring-boot-maven-plugin”和“ maven-compiler-plugin”之间有什么区别?

使用nar-maven-plugin的Spring-boot-maven-plugin重新打包目标错误

spring-boot-maven-plugin spring-boot.run.main-class被忽略(Groovy)

Spring Boot无法运行maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter

Spring Boot Maven插件

spring-boot-maven-plugin打破了兄弟模块的依赖关系

使用JaCoCo和spring-boot-maven-plugin生成代码覆盖率

Spring Boot Core依赖项被maven-dependency-plugin视为未使用

spring-boot-maven-plugin没有将依赖类拉入jar

Spring-Boot-Maven-Plugin,无法实例化接口org.springframework.context.ApplicationContextInitializer

龙目岛不适用于spring-boot-maven-plugin

使用Maven-Failsafe-plugin spring-boot 1.4进行集成测试时出现TypeNotPresentExceptionProxy错误

Maven Docker问题Java Spring Boot无法执行目标io.fabric8:docker-maven-plugin

无法执行目标org.springframework.boot:spring-boot-maven-plugin:2.2.2.RELEASE:run

在插件org.springframework.boot:spring-boot-maven-plugin:1.1.4.RELEASE中找不到目标''

Spring Boot Integration测试随机空闲端口

使用Spring Boot的Maven模块

ProGuard + Spring Boot + Maven插件

Maven Spring Boot编译失败

Spring Boot无法在端口80上启动

在Spring Boot JMS中更改ActiveMQ代理JMX端口1099

运行npm build时无法访问vue.js前端(frontend-maven-plugin和spring-boot后端)

使用maven-spring-boot-plugin将类路径添加到SpringBoot命令行开始

maven-cargo2-plugin如何识别我的Spring Boot应用程序已在运行嵌入式Tomcat?

通过appassembler-maven-plugin生成的脚本无法在Spring Boot应用程序中找到主类