Skip to content

Commit f364d71

Browse files
committed
Add LocalManagementPort
Add an annotation alias for the actual management port, similar to what was done for the main context (`LocalServerPort`). See spring-projectsgh-5548
1 parent a4f77ae commit f364d71

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.beans.factory.annotation.Value;
26+
27+
/**
28+
* Annotation at the field or method/constructor parameter level that injects the HTTP
29+
* management port that got allocated at runtime. Provides a convenient alternative for
30+
* <code>&#064;Value(&quot;${local.management.port}&quot;)</code>.
31+
*
32+
* @author Stephane Nicoll
33+
* @since 1.4.0
34+
*/
35+
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
36+
ElementType.ANNOTATION_TYPE })
37+
@Retention(RetentionPolicy.RUNTIME)
38+
@Documented
39+
@Value("${local.management.port}")
40+
public @interface LocalManagementPort {
41+
}

spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323

24-
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
2525
import org.springframework.boot.context.web.LocalServerPort;
2626
import org.springframework.boot.test.context.SpringBootTest;
2727
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -47,7 +47,7 @@ public class SampleActuatorUiApplicationPortTests {
4747
@LocalServerPort
4848
private int port = 9010;
4949

50-
@Value("${local.management.port}")
50+
@LocalManagementPort
5151
private int managementPort = 9011;
5252

5353
@Test

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.junit.runner.RunWith;
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.beans.factory.annotation.Value;
25+
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
2626
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2727
import org.springframework.boot.context.web.LocalServerPort;
2828
import org.springframework.boot.test.context.SpringBootTest;
@@ -53,7 +53,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
5353
@LocalServerPort
5454
private int port = 9010;
5555

56-
@Value("${local.management.port}")
56+
@LocalManagementPort
5757
private int managementPort = 9011;
5858

5959
@Test

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323

24-
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
2525
import org.springframework.boot.context.web.LocalServerPort;
2626
import org.springframework.boot.test.context.SpringBootTest;
2727
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -48,7 +48,7 @@ public class ManagementAddressActuatorApplicationTests {
4848
@LocalServerPort
4949
private int port = 9010;
5050

51-
@Value("${local.management.port}")
51+
@LocalManagementPort
5252
private int managementPort = 9011;
5353

5454
@Test

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.junit.runner.RunWith;
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.beans.factory.annotation.Value;
25+
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
2626
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2727
import org.springframework.boot.context.web.LocalServerPort;
2828
import org.springframework.boot.test.context.SpringBootTest;
@@ -52,7 +52,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
5252
@LocalServerPort
5353
private int port = 9010;
5454

55-
@Value("${local.management.port}")
55+
@LocalManagementPort
5656
private int managementPort = 9011;
5757

5858
@Test

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.junit.runner.RunWith;
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.beans.factory.annotation.Value;
25+
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
2626
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2727
import org.springframework.boot.context.web.LocalServerPort;
2828
import org.springframework.boot.test.context.SpringBootTest;
@@ -52,7 +52,7 @@ public class ManagementPortSampleActuatorApplicationTests {
5252
@LocalServerPort
5353
private int port = 9010;
5454

55-
@Value("${local.management.port}")
55+
@LocalManagementPort
5656
private int managementPort = 9011;
5757

5858
@Test

0 commit comments

Comments
 (0)