From cd23de6ed55ff2d27981a0f267a51e2130857097 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 19 Jul 2017 10:10:11 -0700 Subject: [PATCH 1/2] Add more HealthIndicatorAutoConfiguration ordering Update HealthIndicatorAutoConfiguration to ensure that it is configured after ActiveMQAutoConfiguration. Fixes gh-9793 --- .../autoconfigure/HealthIndicatorAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java index 4640ad8484..f371e0ee2a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java @@ -66,6 +66,7 @@ import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetada import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders; import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; +import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration; import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; @@ -95,7 +96,7 @@ import org.springframework.mail.javamail.JavaMailSenderImpl; */ @Configuration @AutoConfigureBefore({ EndpointAutoConfiguration.class }) -@AutoConfigureAfter({ CassandraAutoConfiguration.class, +@AutoConfigureAfter({ ActiveMQAutoConfiguration.class, CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class, CouchbaseDataAutoConfiguration.class, DataSourceAutoConfiguration.class, ElasticsearchAutoConfiguration.class, JestAutoConfiguration.class, JmsAutoConfiguration.class, From 68910f2b8fc14b483009cbf793425823c85e9d2e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 19 Jul 2017 10:18:55 -0700 Subject: [PATCH 2/2] Polish --- .../dropwizard/DropwizardMetricServices.java | 2 +- .../condition/AllNestedConditions.java | 8 ++++-- .../condition/AnyNestedCondition.java | 8 ++++-- .../condition/NoneNestedConditions.java | 8 ++++-- ...ServerTokenServicesConfigurationTests.java | 9 +++--- .../boot/ExitCodeApplication.java | 10 +++---- .../CorsSampleActuatorApplicationTests.java | 28 +++++++++---------- 7 files changed, 40 insertions(+), 33 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java index 571841d7a1..e693dd1d87 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AllNestedConditions.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AllNestedConditions.java index b5bb8fe7c6..853937732e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AllNestedConditions.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AllNestedConditions.java @@ -43,9 +43,11 @@ import org.springframework.context.annotation.Condition; * } * *

- * The {@link ConfigurationPhase} should be specified according to the conditions that - * are defined. In the example above, all conditions are static and can be evaluated - * early so {@code PARSE_CONFIGURATION} is a right fit. + * The + * {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase + * ConfigurationPhase} should be specified according to the conditions that are defined. + * In the example above, all conditions are static and can be evaluated early so + * {@code PARSE_CONFIGURATION} is a right fit. * * @author Phillip Webb * @since 1.3.0 diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AnyNestedCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AnyNestedCondition.java index 462bed55b1..6c898be2bc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AnyNestedCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AnyNestedCondition.java @@ -45,9 +45,11 @@ import org.springframework.core.annotation.Order; * } * *

- * The {@link ConfigurationPhase} should be specified according to the conditions that - * are defined. In the example above, all conditions are static and can be evaluated - * early so {@code PARSE_CONFIGURATION} is a right fit. + * The + * {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase + * ConfigurationPhase} should be specified according to the conditions that are defined. + * In the example above, all conditions are static and can be evaluated early so + * {@code PARSE_CONFIGURATION} is a right fit. * * @author Phillip Webb * @since 1.2.0 diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditions.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditions.java index 2a164b74d1..3d2c1ba322 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditions.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditions.java @@ -43,9 +43,11 @@ import org.springframework.context.annotation.Condition; * } * *

- * The {@link ConfigurationPhase} should be specified according to the conditions that - * are defined. In the example above, all conditions are static and can be evaluated - * early so {@code PARSE_CONFIGURATION} is a right fit. + * The + * {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase + * ConfigurationPhase} should be specified according to the conditions that are defined. + * In the example above, all conditions are static and can be evaluated early so + * {@code PARSE_CONFIGURATION} is a right fit. * * @author Phillip Webb * @since 1.3.0 diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java index 10b2733070..0cc434c562 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java @@ -264,8 +264,8 @@ public class ResourceServerTokenServicesConfigurationTests { EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys"); this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class, - ResourceConfiguration.class) - .environment(this.environment).web(false).run(); + ResourceConfiguration.class).environment(this.environment).web(false) + .run(); assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1); } @@ -273,8 +273,9 @@ public class ResourceServerTokenServicesConfigurationTests { public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception { EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY); - this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class) - .environment(this.environment).web(false).run(); + this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, + ResourceConfiguration.class).environment(this.environment).web(false) + .run(); assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1); } diff --git a/spring-boot-docs/src/main/java/org/springframework/boot/ExitCodeApplication.java b/spring-boot-docs/src/main/java/org/springframework/boot/ExitCodeApplication.java index 6a6d80ad7e..3af123333c 100644 --- a/spring-boot-docs/src/main/java/org/springframework/boot/ExitCodeApplication.java +++ b/spring-boot-docs/src/main/java/org/springframework/boot/ExitCodeApplication.java @@ -28,11 +28,6 @@ import org.springframework.context.annotation.Bean; @SpringBootApplication public class ExitCodeApplication { - public static void main(String[] args) { - System.exit(SpringApplication.exit( - SpringApplication.run(ExitCodeApplication.class, args))); - } - @Bean public ExitCodeGenerator exitCodeGenerator() { return new ExitCodeGenerator() { @@ -43,5 +38,10 @@ public class ExitCodeApplication { }; } + public static void main(String[] args) { + System.exit(SpringApplication + .exit(SpringApplication.run(ExitCodeApplication.class, args))); + } + } // end::example[] diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/CorsSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/CorsSampleActuatorApplicationTests.java index dffe86f177..ba96211b9f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/CorsSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/CorsSampleActuatorApplicationTests.java @@ -51,37 +51,37 @@ public class CorsSampleActuatorApplicationTests { @Test public void sensitiveEndpointShouldReturnUnauthorized() throws Exception { - ResponseEntity entity = this.testRestTemplate.getForEntity("/env", Map.class); + ResponseEntity entity = this.testRestTemplate.getForEntity("/env", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void preflightRequestForInsensitiveShouldReturnOk() throws Exception { RequestEntity healthRequest = RequestEntity.options(new URI("/health")) - .header("Origin","http://localhost:8080") - .header("Access-Control-Request-Method", "GET") - .build(); - ResponseEntity exchange = this.testRestTemplate.exchange(healthRequest, Map.class); + .header("Origin", "http://localhost:8080") + .header("Access-Control-Request-Method", "GET").build(); + ResponseEntity exchange = this.testRestTemplate.exchange(healthRequest, + Map.class); assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void preflightRequestForSensitiveEndpointShouldReturnOk() throws Exception { RequestEntity entity = RequestEntity.options(new URI("/env")) - .header("Origin","http://localhost:8080") - .header("Access-Control-Request-Method", "GET") - .build(); - ResponseEntity env = this.testRestTemplate.exchange(entity, Map.class); + .header("Origin", "http://localhost:8080") + .header("Access-Control-Request-Method", "GET").build(); + ResponseEntity env = this.testRestTemplate.exchange(entity, Map.class); assertThat(env.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test - public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception { + public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() + throws Exception { RequestEntity entity = RequestEntity.options(new URI("/health")) - .header("Origin","http://localhost:9095") - .header("Access-Control-Request-Method", "GET") - .build(); - ResponseEntity exchange = this.testRestTemplate.exchange(entity, byte[].class); + .header("Origin", "http://localhost:9095") + .header("Access-Control-Request-Method", "GET").build(); + ResponseEntity exchange = this.testRestTemplate.exchange(entity, + byte[].class); assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); }