簡體   English   中英

spring-boot-maven-plugin - 在隨機端口啟動 JMX

[英]spring-boot-maven-plugin - start JMX at random port

關於如何隨機啟動 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 不工作。

請問如何隨機啟動?

謝謝

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM