diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java index 3b43c9c466..8a3f81c8f9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java @@ -86,9 +86,8 @@ public class CloudFoundryWebEndpointDiscovererTests { private void load(Function timeToLive, PathMapper endpointPathMapper, Class configuration, Consumer consumer) { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - configuration); - try { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + configuration)) { ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( DefaultConversionService.getSharedInstance()); EndpointMediaTypes mediaTypes = new EndpointMediaTypes( @@ -101,9 +100,6 @@ public class CloudFoundryWebEndpointDiscovererTests { Collections.emptyList()); consumer.accept(discoverer); } - finally { - context.close(); - } } @Configuration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java index d4906b9dd3..7958981b86 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java @@ -163,15 +163,11 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { private void load(Class configuration, Consumer clientConsumer) { BiConsumer consumer = (context, client) -> clientConsumer.accept(client); - AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( - configuration, CloudFoundryMvcConfiguration.class); - try { + try (AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( + configuration, CloudFoundryMvcConfiguration.class)) { consumer.accept(context, WebTestClient.bindToServer() .baseUrl("http://localhost:" + getPort(context)).build()); } - finally { - context.close(); - } } private String mockAccessToken() { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java index 8ca57e42c8..300f7a4f1c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java @@ -252,9 +252,8 @@ public class WebEndpointDiscovererTests { private void load(Function timeToLive, PathMapper endpointPathMapper, Class configuration, Consumer consumer) { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - configuration); - try { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + configuration)) { ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( DefaultConversionService.getSharedInstance()); EndpointMediaTypes mediaTypes = new EndpointMediaTypes( @@ -267,9 +266,6 @@ public class WebEndpointDiscovererTests { Collections.emptyList()); consumer.accept(discoverer); } - finally { - context.close(); - } } private Map mapEndpoints(