From 2526a54e313843821ae0b6918f28018175049528 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 14 Mar 2016 14:19:55 +0100 Subject: [PATCH] Polish contribution Closes gh-5337 --- .../EndpointMvcIntegrationTests.java | 2 +- ...ointServerContextPathIntegrationTests.java | 2 +- ...igurationCustomFilterContextPathTests.java | 2 +- ...utoConfigurationCustomFilterPathTests.java | 2 +- ...rationCustomObjectMapperProviderTests.java | 2 +- ...gurationCustomServletContextPathTests.java | 2 +- ...toConfigurationCustomServletPathTests.java | 2 +- ...toConfigurationDefaultFilterPathTests.java | 2 +- ...oConfigurationDefaultServletPathTests.java | 2 +- ...onfigurationObjectMapperProviderTests.java | 2 +- ...utoConfigurationServletContainerTests.java | 2 +- ...figurationWithoutApplicationPathTests.java | 2 +- ...serInfoTokenServicesRefreshTokenTests.java | 2 +- .../RemappedErrorViewIntegrationTests.java | 2 +- spring-boot-docs/src/main/asciidoc/howto.adoc | 11 +-- .../SampleActuatorLog4J2ApplicationTests.java | 4 +- .../SampleActuatorUiApplicationPortTests.java | 3 +- .../ui/SampleActuatorUiApplicationTests.java | 4 +- ...pertiesSampleActuatorApplicationTests.java | 4 +- ...AndPathSampleActuatorApplicationTests.java | 3 +- ...agementSampleActuatorApplicationTests.java | 4 +- ...nsecureSampleActuatorApplicationTests.java | 4 +- ...gementAddressActuatorApplicationTests.java | 3 +- ...entPathSampleActuatorApplicationTests.java | 4 +- ...AndPathSampleActuatorApplicationTests.java | 3 +- ...entPortSampleActuatorApplicationTests.java | 3 +- ...agementSampleActuatorApplicationTests.java | 4 +- .../actuator/NonSensitiveHealthTests.java | 4 +- .../SampleActuatorApplicationTests.java | 4 +- ...nsecureSampleActuatorApplicationTests.java | 4 +- ...letPathSampleActuatorApplicationTests.java | 4 +- ...hutdownSampleActuatorApplicationTests.java | 4 +- .../SampleAtmosphereApplicationTests.java | 3 +- .../SampleHateoasApplicationTests.java | 4 +- .../SampleHypermediaUiApplicationTests.java | 4 +- ...pleHypermediaApplicationHomePageTests.java | 4 +- .../jersey/SampleJerseyApplicationTests.java | 4 +- .../SampleJersey1ApplicationTests.java | 4 +- .../ssl/SampleJettySslApplicationTests.java | 4 +- .../jetty/SampleJettyApplicationTests.java | 4 +- .../ssl/SampleJetty8SslApplicationTests.java | 4 +- .../jetty8/SampleJetty8ApplicationTests.java | 4 +- .../SampleJetty93ApplicationTests.java | 4 +- .../SampleServletApplicationTests.java | 4 +- .../testng/SampleTestNGApplicationTests.java | 4 +- .../jsp/SampleWebJspApplicationTests.java | 4 +- ...leTomcatTwoConnectorsApplicationTests.java | 4 +- .../ssl/SampleTomcatSslApplicationTests.java | 5 +- ...igurationSampleTomcatApplicationTests.java | 4 +- .../tomcat/SampleTomcatApplicationTests.java | 4 +- .../jsp/SampleWebJspApplicationTests.java | 4 +- .../SampleTraditionalApplicationTests.java | 4 +- .../SampleUndertowSslApplicationTests.java | 4 +- .../SampleUndertowApplicationTests.java | 4 +- .../SampleWebFreeMarkerApplicationTests.java | 4 +- .../SampleGroovyTemplateApplicationTests.java | 4 +- .../jsp/SampleWebJspApplicationTests.java | 4 +- .../SampleMethodSecurityApplicationTests.java | 4 +- .../SampleWebMustacheApplicationTests.java | 4 +- ...SampleWebSecureCustomApplicationTests.java | 5 +- .../github/SampleGithubApplicationTests.java | 4 +- ...SampleWebSecureCustomApplicationTests.java | 4 +- .../secure/SampleSecureApplicationTests.java | 4 +- .../SampleWebStaticApplicationTests.java | 5 +- .../web/ui/SampleWebUiApplicationTests.java | 5 +- .../SampleWebVelocityApplicationTests.java | 4 +- .../SampleWebSocketsApplicationTests.java | 3 +- .../SampleWebSocketsApplicationTests.java | 3 +- .../SampleWebSocketsApplicationTests.java | 3 +- .../sample/ws/SampleWsApplicationTests.java | 5 +- .../boot/test/WebIntegrationTest.java | 5 +- ...SpringApplicationIntegrationTestTests.java | 2 +- ...ingApplicationWebIntegrationTestTests.java | 2 +- .../web}/LocalServerPort.java | 13 +++- .../boot/bind/LocalServerPortTests.java | 67 ------------------- .../src/test/resources/some.properties | 1 - 76 files changed, 146 insertions(+), 199 deletions(-) rename spring-boot/src/main/java/org/springframework/boot/{bind => context/web}/LocalServerPort.java (66%) delete mode 100644 spring-boot/src/test/java/org/springframework/boot/bind/LocalServerPortTests.java diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index 9dcef9086019..ed194491259d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -47,7 +47,7 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java index b386751cfd81..2f46ea8acffc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java @@ -23,7 +23,7 @@ import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java index 5d70900db58c..d89dd6283c94 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterContextPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java index 869b014512b2..dfdd4d8e847f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index d2fdfad5b9f4..afc94ad4a77a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java index 1f75a0a961c9..f9a3f65e6e63 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletContextPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java index 30780bb6f534..51b95043ec2b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java index c8439706c3e5..f73d9eb029c9 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java @@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultFilterPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java index 8a14ae5b631d..9911b6707a6e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java @@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java index fb8df62eb38a..62aa3ab05f51 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -36,7 +36,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java index 77eda0b361be..d30cbe78e501 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java @@ -33,8 +33,8 @@ import org.springframework.boot.autoconfigure.test.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.SpringApplicationConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java index 095d878f5c15..c42eaaf74dd4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java @@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java index da41b87e52aa..ef32f2571bed 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java @@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.bind.LocalServerPort; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java index 787d00c538fa..523cb8df8369 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java @@ -21,11 +21,11 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.RemappedErrorViewIntegrationTests.TestConfiguration; -import org.springframework.boot.bind.LocalServerPort; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.ErrorPage; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 062e13914784..7cc34c7b91fd 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -454,7 +454,7 @@ that and be sure that it has initialized is to add a `@Bean` of type out of the event when it is published. A useful practice for use with `@WebIntegrationTest` is to set `server.port=0` -and then inject the actual ('`local`') port as a `@Value`. For example: +and then inject the actual port. For example: [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- @@ -466,7 +466,7 @@ and then inject the actual ('`local`') port as a `@Value`. For example: @Autowired EmbeddedWebApplicationContext server; - @Value("${local.server.port}") + @LocalServerPort int port; // ... @@ -476,9 +476,10 @@ and then inject the actual ('`local`') port as a `@Value`. For example: [NOTE] ==== -Don't try to inject the port with `@Value` in a regular application. As we just saw, the -value is only set once the container has initialized; contrary to a test, application code -callbacks are processed early (i.e. before the value is actually available). +`@LocalServerPort` is a meta-annotation for `@Value("${local.server.port}")`. Don't try +to inject the port in a regular application. As we just saw, the value is only set once +the container has initialized; contrary to a test, application code callbacks are +processed early (i.e. before the value is actually available). ==== diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java index c839d2fc790f..b6c03c9075d7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +43,7 @@ @DirtiesContext public class SampleActuatorLog4J2ApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index 53aff3a71312..080874f3b8df 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +44,7 @@ @DirtiesContext public class SampleActuatorUiApplicationPortTests { - @Value("${local.server.port}") + @LocalServerPort private int port = 9010; @Value("${local.management.port}") diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index 290ec3f7d5ea..bd0e90584b51 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ @DirtiesContext public class SampleActuatorUiApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 5ab18b640d8e..f5a36d94c9b7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -22,8 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -50,7 +50,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index 235d5d480f0c..33de1082ea82 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -49,7 +50,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port = 9010; @Value("${local.management.port}") diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java index 878170456a25..c750fa557eb9 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -46,7 +46,7 @@ @ActiveProfiles("unsecure-management") public class InsecureManagementSampleActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java index daa7ba02a719..4d974fb3eb1e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -44,7 +44,7 @@ @DirtiesContext public class InsecureSampleActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index d70042e1b3cd..68446dc65b26 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -44,7 +45,7 @@ @DirtiesContext public class ManagementAddressActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port = 9010; @Value("${local.management.port}") diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java index c8a8e7e82381..71795d06a85d 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +43,7 @@ @DirtiesContext public class ManagementPathSampleActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 6fee514bfc1e..f164fb3625d5 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -49,7 +50,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port = 9010; @Value("${local.management.port}") diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index f1b6eba29e31..606237495822 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +49,7 @@ public class ManagementPortSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port = 9010; @Value("${local.management.port}") diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index 85b2abdf11a5..26dabb12ff5f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -22,8 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ public class NoManagementSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port = 0; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java index 50b95a21a7b1..a2aed47d0ed0 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -41,7 +41,7 @@ @DirtiesContext public class NonSensitiveHealthTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index a65fce50e3f4..71b3cd9c9a6a 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -24,9 +24,9 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -56,7 +56,7 @@ public class SampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java index 1049db399638..24a9d2683817 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -45,7 +45,7 @@ @DirtiesContext public class ServletPathInsecureSampleActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java index 6c70f465ed0b..dbb885dd3204 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +43,7 @@ @DirtiesContext public class ServletPathSampleActuatorApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java index b16ca933bbc9..994982602f9c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -22,8 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ public class ShutdownSampleActuatorApplicationTests { @Autowired private SecurityProperties security; - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index 90acd1c03c0e..08e03de9baff 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -29,6 +29,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; @@ -52,7 +53,7 @@ public class SampleAtmosphereApplicationTests { private static Log logger = LogFactory.getLog(SampleAtmosphereApplicationTests.class); - @Value("${local.server.port}") + @LocalServerPort private int port = 1234; @Test diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java index d28813dd0665..3a47d3bff6dc 100644 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -40,7 +40,7 @@ @WebIntegrationTest(randomPort = true) public class SampleHateoasApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java index 18dad16e3fb9..2b59846209ee 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -40,7 +40,7 @@ @WebIntegrationTest(value = { "management.context-path=" }, randomPort = true) public class SampleHypermediaUiApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java index 68cfef83088d..0abc46a5a49c 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -40,7 +40,7 @@ @WebIntegrationTest(randomPort = true) public class SampleHypermediaApplicationHomePageTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index 90e2217a0f73..7a1508c4e364 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -35,7 +35,7 @@ @WebIntegrationTest(randomPort = true) public class SampleJerseyApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; private RestTemplate restTemplate = new TestRestTemplate(); diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java index 7b871e179ffd..14817d4e8538 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -32,7 +32,7 @@ @WebIntegrationTest(randomPort = true) public class SampleJersey1ApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java index 78ceca9e311d..1ac001071fbc 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -47,7 +47,7 @@ @DirtiesContext public class SampleJettySslApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java index 46c3343860d6..71e0f4f89b7d 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleJettyApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java index 0ee6e755b944..36a0dad3ced6 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -47,7 +47,7 @@ @DirtiesContext public class SampleJetty8SslApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java index 74ef22dfc311..c4347ee702d4 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleJetty8ApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java index a416046351d9..84f1398053a2 100644 --- a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleJetty93ApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index e912f023df1d..86266e384394 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -20,8 +20,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +43,7 @@ @DirtiesContext public class SampleServletApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Autowired diff --git a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java index 9d29ad1b3cbb..665cc417097d 100644 --- a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java @@ -18,7 +18,7 @@ import org.testng.annotations.Test; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -39,7 +39,7 @@ @DirtiesContext public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java index 560a43a6d908..b0d921621064 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -41,7 +41,7 @@ @DirtiesContext public class SampleWebJspApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java index f3ff08f38e24..28103007b08e 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -31,7 +31,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ApplicationContext; @@ -56,7 +56,7 @@ @DirtiesContext public class SampleTomcatTwoConnectorsApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private String port; @Autowired diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java index 3e3b088507ef..7454d58f9019 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java @@ -23,9 +23,8 @@ import org.apache.http.ssl.SSLContextBuilder; import org.junit.Test; import org.junit.runner.RunWith; -import sample.tomcat.ssl.SampleTomcatSslApplication; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +42,7 @@ @DirtiesContext public class SampleTomcatSslApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index f485b0ba8cbf..3e946295ec34 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -22,7 +22,6 @@ import sample.tomcat.service.HelloWorldService; import sample.tomcat.web.SampleController; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; @@ -30,6 +29,7 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -54,7 +54,7 @@ @DirtiesContext public class NonAutoConfigurationSampleTomcatApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Configuration diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index ecf76a0dfc3c..763b8d3d75ce 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleTomcatApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java index 8ac3dae30415..89fe80034c1c 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -41,7 +41,7 @@ @DirtiesContext public class SampleWebJspApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java index 21047b733b7a..081890a326db 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -41,7 +41,7 @@ @DirtiesContext public class SampleTraditionalApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java index 48de246594cf..9971d44245c3 100644 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -47,7 +47,7 @@ @DirtiesContext public class SampleUndertowSslApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java index 6c500a6b778b..f9ce1958e0d5 100644 --- a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleUndertowApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java index 4dc558fd6834..3c2879dad756 100644 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ @DirtiesContext public class SampleWebFreeMarkerApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java index 2f7e6877db59..4b7c50620794 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -45,7 +45,7 @@ @DirtiesContext public class SampleGroovyTemplateApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java index 4bce22b041c3..62b3f775754c 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -41,7 +41,7 @@ @DirtiesContext public class SampleWebJspApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index 79cea1633d0a..e35f951f2ec7 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleMethodSecurityApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java index c797029ba809..7d270c7bae2c 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ @DirtiesContext public class SampleWebMustacheApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java index e1b876faf416..dd012d146605 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java @@ -22,9 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; -import sample.web.secure.custom.SampleWebSecureCustomApplication; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -52,7 +51,7 @@ @DirtiesContext public class SampleWebSecureCustomApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java index b4e9811efe89..91fa30fa3f95 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -44,7 +44,7 @@ @DirtiesContext public class SampleGithubApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java index 64ed37e953e6..87fed77debd6 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleWebSecureCustomApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java index 4584a5def415..83664e084f6b 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -51,7 +51,7 @@ @DirtiesContext public class SampleSecureApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java index 994775a0897c..93a6c538a37d 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java @@ -18,9 +18,8 @@ import org.junit.Test; import org.junit.runner.RunWith; -import sample.web.staticcontent.SampleWebStaticApplication; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -43,7 +42,7 @@ @DirtiesContext public class SampleWebStaticApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port = 0; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java index ed0495eaaec6..ae4feb3359ce 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java @@ -20,9 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; -import sample.web.ui.SampleWebUiApplication; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -46,7 +45,7 @@ @DirtiesContext public class SampleWebUiApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java index 2dceeb862c1f..f4ef0379f7ea 100644 --- a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; @@ -48,7 +48,7 @@ @DirtiesContext public class SampleWebVelocityApplicationTests { - @Value("${local.server.port}") + @LocalServerPort private int port; @Test diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index 74811a35c95d..a788422f8cc7 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; @@ -52,7 +53,7 @@ public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - @Value("${local.server.port}") + @LocalServerPort private int port = 1234; @Test diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index ba02e9dcc834..667f20e42f39 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; @@ -52,7 +53,7 @@ public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - @Value("${local.server.port}") + @LocalServerPort private int port = 1234; @Test diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index d3b97ff60c0d..2b037fcc12a3 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -33,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; @@ -53,7 +54,7 @@ public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - @Value("${local.server.port}") + @LocalServerPort private int port = 1234; @Test diff --git a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java index dff13f2fe339..38fbe205458d 100644 --- a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package sample.ws; import java.io.StringReader; @@ -25,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; @@ -44,7 +45,7 @@ public class SampleWsApplicationTests { private WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); - @Value("${local.server.port}") + @LocalServerPort private int serverPort; @Before diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java index 278580ebf61c..8894e0640349 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java @@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; @@ -56,8 +57,8 @@ /** * Convenience attribute that can be used to set a {@code server.port=0} * {@link Environment} property which usually triggers listening on a random port. - * Often used in conjunction with a @Value("${local.server.port}") - * injected field on the test. + * Often used in conjunction with a {@link LocalServerPort} injected field on the + * test. * @return if a random port should be used */ boolean randomPort() default false; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java index 05569f458985..2c05b22b54ab 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java @@ -23,9 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.bind.LocalServerPort; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java index b25b3247695a..d3a6f5e984ae 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java @@ -23,9 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.bind.LocalServerPort; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.SpringApplicationWebIntegrationTestTests.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/LocalServerPort.java b/spring-boot/src/main/java/org/springframework/boot/context/web/LocalServerPort.java similarity index 66% rename from spring-boot/src/main/java/org/springframework/boot/bind/LocalServerPort.java rename to spring-boot/src/main/java/org/springframework/boot/context/web/LocalServerPort.java index c6beaa53d1e0..3b11b297a0cc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/LocalServerPort.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/LocalServerPort.java @@ -14,20 +14,27 @@ * limitations under the License. */ -package org.springframework.boot.bind; +package org.springframework.boot.context.web; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import org.springframework.beans.factory.annotation.Value; /** - * Meta annotation for replacement of property local.server.port. Can be used instead of - * @Value("${local.server.port}") + * Annotation at the field or method/constructor parameter level + * that injects the HTTP port that got allocated at runtime. + *

+ * Convenient meta-annotation replacing {@code @LocalServerPort}. * * @author Anand Shah + * @author Stephane Nicoll + * @since 1.4.0 */ @Value("${local.server.port}") +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface LocalServerPort { diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/LocalServerPortTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/LocalServerPortTests.java deleted file mode 100644 index 7921aa29e108..000000000000 --- a/spring-boot/src/test/java/org/springframework/boot/bind/LocalServerPortTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.bind; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.bind.PropertySourcesBindingTests.TestConfig; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link LocalServerPort} annotation based injection of local.server.port - * property. - * - * @author Anand Shah - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestConfig.class) -public class LocalServerPortTests { - - private ConfigurableApplicationContext context; - - @Value("${local.server.port:}") - private String localServerPortFromValue; - - @LocalServerPort - private String localServerPortFromAnnotation; - - @Test - public void testLocalServerPortAnnotation() { - SpringApplication application = new SpringApplication(LocalServerPortTests.class); - application.setWebEnvironment(true); - - this.context = application.run(); - - assertThat(this.localServerPortFromAnnotation).isNotNull().isNotEmpty() - .isEqualTo(this.localServerPortFromValue).isEqualTo( - this.context.getEnvironment().getProperty("local.server.port")); - } - - @Bean - public JettyEmbeddedServletContainerFactory container() { - return new JettyEmbeddedServletContainerFactory(8081); - } -} diff --git a/spring-boot/src/test/resources/some.properties b/spring-boot/src/test/resources/some.properties index e0efc305ac03..a1e02b448092 100644 --- a/spring-boot/src/test/resources/some.properties +++ b/spring-boot/src/test/resources/some.properties @@ -2,4 +2,3 @@ foo=spam bar=some spam=bucket the-name=name -local.server.port=8081