From b28d537c789f8b43071e3099b448e6bc365789ae Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2017 13:48:49 -0800 Subject: [PATCH 1/5] Disable unwanted m2e activations Add m2e activation properties to disable unwanted Eclipse facets. --- spring-boot-parent/pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index 1bcf0300dd..143b3d0980 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.springframework.boot @@ -752,6 +753,12 @@ m2e.version + + false + false + false + false + From 43d432a527b94807883e204a41299d72164f08c9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2017 14:11:47 -0800 Subject: [PATCH 2/5] Polish --- .../HealthIndicatorAutoConfiguration.java | 3 ++- .../actuate/health/LdapHealthIndicator.java | 1 + .../HealthIndicatorAutoConfigurationTests.java | 8 ++++---- .../health/LdapHealthIndicatorTests.java | 18 ++++++++++-------- .../LdapRepositoriesAutoConfiguration.java | 3 +-- .../security/SecurityProperties.java | 4 ++-- .../DefaultUserInfoRestTemplateFactory.java | 4 +++- ...sourceServerTokenServicesConfiguration.java | 3 ++- ...epositoryRestMvcAutoConfigurationTests.java | 9 ++++++--- ...eServerTokenServicesConfigurationTests.java | 6 +++--- 10 files changed, 34 insertions(+), 25 deletions(-) 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 de30335deb..e6855de2f7 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 @@ -244,7 +244,8 @@ public class HealthIndicatorAutoConfiguration { private final Map ldapOperations; - public LdapHealthIndicatorConfiguration(Map ldapOperations) { + public LdapHealthIndicatorConfiguration( + Map ldapOperations) { this.ldapOperations = ldapOperations; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/LdapHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/LdapHealthIndicator.java index 3456b4703b..668c1df591 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/LdapHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/LdapHealthIndicator.java @@ -57,6 +57,7 @@ public class LdapHealthIndicator extends AbstractHealthIndicator { } return null; } + } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 9b3a33831d..36630d4ab0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -541,8 +541,8 @@ public class HealthIndicatorAutoConfigurationTests { public void ldapHealthIndicator() throws Exception { EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); - this.context.register(LdapConfiguration.class, - ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); + this.context.register(LdapConfiguration.class, ManagementServerProperties.class, + HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); @@ -556,8 +556,8 @@ public class HealthIndicatorAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false", "management.health.ldap.enabled:false"); - this.context.register(LdapConfiguration.class, - ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); + this.context.register(LdapConfiguration.class, ManagementServerProperties.class, + HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java index 1551506c0b..e2a6afebf5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java @@ -62,31 +62,33 @@ public class LdapHealthIndicatorTests { this.context.register(LdapAutoConfiguration.class, LdapDataAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, - EndpointAutoConfiguration.class, - HealthIndicatorAutoConfiguration.class); + EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); this.context.refresh(); LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class); assertThat(ldapTemplate).isNotNull(); - LdapHealthIndicator healthIndicator = this.context.getBean( - LdapHealthIndicator.class); + LdapHealthIndicator healthIndicator = this.context + .getBean(LdapHealthIndicator.class); assertThat(healthIndicator).isNotNull(); } @Test + @SuppressWarnings("unchecked") public void ldapIsUp() { LdapTemplate ldapTemplate = mock(LdapTemplate.class); - given(ldapTemplate.executeReadOnly(any(ContextExecutor.class))).willReturn("3"); + given(ldapTemplate.executeReadOnly((ContextExecutor) any())) + .willReturn("3"); LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails().get("version")).isEqualTo("3"); - verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class)); + verify(ldapTemplate).executeReadOnly((ContextExecutor) any()); } @Test + @SuppressWarnings("unchecked") public void ldapIsDown() { LdapTemplate ldapTemplate = mock(LdapTemplate.class); - given(ldapTemplate.executeReadOnly(any(ContextExecutor.class))) + given(ldapTemplate.executeReadOnly((ContextExecutor) any())) .willThrow(new CommunicationException( new javax.naming.CommunicationException("Connection failed"))); LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate); @@ -94,7 +96,7 @@ public class LdapHealthIndicatorTests { assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat((String) health.getDetails().get("error")) .contains("Connection failed"); - verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class)); + verify(ldapTemplate).executeReadOnly((ContextExecutor) any()); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfiguration.java index 1cc0bd44b8..8817c47335 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfiguration.java @@ -28,8 +28,7 @@ import org.springframework.data.ldap.repository.LdapRepository; import org.springframework.data.ldap.repository.support.LdapRepositoryFactoryBean; /** - * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP - * Repositories. + * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP Repositories. * * @author Eddú Meléndez * @since 1.5.0 diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java index 36d99a3fe6..12cc1f723e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java @@ -48,8 +48,8 @@ public class SecurityProperties implements SecurityPrerequisite { /** * Order applied to the WebSecurityConfigurerAdapter that is used to configure basic * authentication for application endpoints. If you want to add your own - * authentication for all or some of those endpoints the best thing to do is to add your - * own WebSecurityConfigurerAdapter with lower order. + * authentication for all or some of those endpoints the best thing to do is to add + * your own WebSecurityConfigurerAdapter with lower order. */ public static final int BASIC_AUTH_ORDER = Ordered.LOWEST_PRECEDENCE - 5; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/DefaultUserInfoRestTemplateFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/DefaultUserInfoRestTemplateFactory.java index c1be6054e7..ac30aeec06 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/DefaultUserInfoRestTemplateFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/DefaultUserInfoRestTemplateFactory.java @@ -66,11 +66,13 @@ public class DefaultUserInfoRestTemplateFactory implements UserInfoRestTemplateF this.oauth2ClientContext = oauth2ClientContext.getIfAvailable(); } + @Override public OAuth2RestTemplate getUserInfoRestTemplate() { if (this.oauth2RestTemplate == null) { this.oauth2RestTemplate = createOAuth2RestTemplate( this.details == null ? DEFAULT_RESOURCE_DETAILS : this.details); - this.oauth2RestTemplate.getInterceptors().add(new AcceptJsonRequestInterceptor()); + this.oauth2RestTemplate.getInterceptors() + .add(new AcceptJsonRequestInterceptor()); AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider(); accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer()); this.oauth2RestTemplate.setAccessTokenProvider(accessTokenProvider); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java index f5729b6b26..78c64d126c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java @@ -88,7 +88,8 @@ public class ResourceServerTokenServicesConfiguration { ObjectProvider> customizers, ObjectProvider details, ObjectProvider oauth2ClientContext) { - return new DefaultUserInfoRestTemplateFactory(customizers, details, oauth2ClientContext); + return new DefaultUserInfoRestTemplateFactory(customizers, details, + oauth2ClientContext); } @Configuration diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java index f238b73b6f..dc2e7c8951 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java @@ -222,13 +222,16 @@ public class RepositoryRestMvcAutoConfigurationTests { } static class TestRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter { + @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + public void configureRepositoryRestConfiguration( + RepositoryRestConfiguration config) { config.setRepositoryDetectionStrategy(RepositoryDetectionStrategies.ALL); - config.setDefaultMediaType(MediaType.parseMediaType( - "application/my-custom-json")); + config.setDefaultMediaType( + MediaType.parseMediaType("application/my-custom-json")); config.setMaxPageSize(78); } + } } 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 9e3a196265..3deccd09f8 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 @@ -220,7 +220,7 @@ public class ResourceServerTokenServicesConfigurationTests { "security.oauth2.resource.userInfoUri:http://example.com"); this.context = new SpringApplicationBuilder( CustomUserInfoRestTemplateFactory.class, ResourceConfiguration.class) - .environment(this.environment).web(false).run(); + .environment(this.environment).web(false).run(); assertThat(this.context.getBeansOfType(UserInfoRestTemplateFactory.class)) .hasSize(1); assertThat(this.context.getBean(UserInfoRestTemplateFactory.class)) @@ -331,8 +331,8 @@ public class ResourceServerTokenServicesConfigurationTests { protected static class CustomUserInfoRestTemplateFactory implements UserInfoRestTemplateFactory { - private final OAuth2RestTemplate restTemplate = - new OAuth2RestTemplate(new AuthorizationCodeResourceDetails()); + private final OAuth2RestTemplate restTemplate = new OAuth2RestTemplate( + new AuthorizationCodeResourceDetails()); @Override public OAuth2RestTemplate getUserInfoRestTemplate() { From 0a6456a7481b1d1c6f42e12a4837938c2e8ee526 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2017 20:27:55 -0800 Subject: [PATCH 3/5] Always use `prefix` config annotation attribute Update use of `@ConfigurationProperties` to prefer the more explicit `prefix` attribute, rather than `value`. See gh-7579 --- .../actuate/autoconfigure/HealthIndicatorProperties.java | 2 +- .../actuate/autoconfigure/MetricFilterProperties.java | 2 +- .../boot/actuate/endpoint/mvc/DocsMvcEndpoint.java | 2 +- .../boot/actuate/endpoint/mvc/HalJsonMvcEndpoint.java | 2 +- .../boot/actuate/endpoint/mvc/HeapdumpMvcEndpoint.java | 2 +- .../health/DiskSpaceHealthIndicatorProperties.java | 2 +- .../actuate/metrics/export/MetricExportProperties.java | 2 +- .../boot/autoconfigure/batch/BatchProperties.java | 2 +- .../autoconfigure/data/rest/RepositoryRestProperties.java | 2 +- .../autoconfigure/elasticsearch/jest/JestProperties.java | 2 +- .../boot/autoconfigure/hazelcast/HazelcastProperties.java | 2 +- .../boot/autoconfigure/info/ProjectInfoProperties.java | 2 +- .../boot/autoconfigure/jdbc/DataSourceConfiguration.java | 8 ++++---- .../boot/autoconfigure/jersey/JerseyProperties.java | 2 +- .../activemq/ActiveMQConnectionFactoryConfiguration.java | 2 +- .../mobile/DeviceDelegatingViewResolverProperties.java | 2 +- .../security/oauth2/OAuth2ClientProperties.java | 2 +- .../oauth2/authserver/AuthorizationServerProperties.java | 2 +- .../OAuth2AuthorizationServerConfiguration.java | 2 +- .../OAuth2ProtectedResourceDetailsConfiguration.java | 2 +- .../oauth2/client/OAuth2RestOperationsConfiguration.java | 2 +- .../security/oauth2/client/OAuth2SsoProperties.java | 2 +- .../oauth2/resource/ResourceServerProperties.java | 2 +- .../boot/autoconfigure/session/SessionProperties.java | 2 +- .../boot/autoconfigure/social/FacebookProperties.java | 2 +- .../boot/autoconfigure/social/LinkedInProperties.java | 2 +- .../boot/autoconfigure/social/TwitterProperties.java | 2 +- .../boot/autoconfigure/thymeleaf/ThymeleafProperties.java | 2 +- .../autoconfigure/transaction/TransactionProperties.java | 2 +- .../transaction/jta/BitronixJtaConfiguration.java | 2 +- .../boot/autoconfigure/web/WebMvcProperties.java | 2 +- .../autoconfigure/webservices/WebServicesProperties.java | 2 +- .../autoconfigure/restdocs/RestDocsAutoConfiguration.java | 2 +- .../web/servlet/MockMvcAutoConfiguration.java | 2 +- .../boot/jta/atomikos/AtomikosProperties.java | 2 +- 35 files changed, 38 insertions(+), 38 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorProperties.java index 6588038133..071586e1bf 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorProperties.java @@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Christian Dupuis * @since 1.2.0 */ -@ConfigurationProperties("management.health.status") +@ConfigurationProperties(prefix = "management.health.status") public class HealthIndicatorProperties { /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterProperties.java index cdbedf4975..3feff10228 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterProperties.java @@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Phillip Webb * @since 1.4.0 */ -@ConfigurationProperties("endpoints.metrics.filter") +@ConfigurationProperties(prefix = "endpoints.metrics.filter") public class MetricFilterProperties { /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/DocsMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/DocsMvcEndpoint.java index 2d8261b161..1816fb14a9 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/DocsMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/DocsMvcEndpoint.java @@ -27,7 +27,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry * @author Dave Syer * @since 1.3.0 */ -@ConfigurationProperties("endpoints.docs") +@ConfigurationProperties(prefix = "endpoints.docs") public class DocsMvcEndpoint extends AbstractNamedMvcEndpoint { private static final String DOCS_LOCATION = "classpath:/META-INF/resources/spring-boot-actuator/docs/"; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HalJsonMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HalJsonMvcEndpoint.java index 33e252bcab..18dfa1ad26 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HalJsonMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HalJsonMvcEndpoint.java @@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author Andy Wilkinson * @since 1.3.0 */ -@ConfigurationProperties("endpoints.actuator") +@ConfigurationProperties(prefix = "endpoints.actuator") public class HalJsonMvcEndpoint extends AbstractNamedMvcEndpoint { private final ManagementServletContext managementServletContext; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HeapdumpMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HeapdumpMvcEndpoint.java index 210ed279ab..b3dde9935c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HeapdumpMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HeapdumpMvcEndpoint.java @@ -54,7 +54,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; * @author Phillip Webb * @since 1.4.0 */ -@ConfigurationProperties("endpoints.heapdump") +@ConfigurationProperties(prefix = "endpoints.heapdump") @HypermediaDisabled public class HeapdumpMvcEndpoint extends AbstractNamedMvcEndpoint { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorProperties.java index bb5929095d..5c8c776ece 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorProperties.java @@ -27,7 +27,7 @@ import org.springframework.util.Assert; * @author Andy Wilkinson * @since 1.2.0 */ -@ConfigurationProperties("management.health.diskspace") +@ConfigurationProperties(prefix = "management.health.diskspace") public class DiskSpaceHealthIndicatorProperties { private static final int MEGABYTES = 1024 * 1024; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java index fb2bc15920..2b26408ede 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java @@ -32,7 +32,7 @@ import org.springframework.util.PatternMatchUtils; * @author Simon Buettner * @since 1.3.0 */ -@ConfigurationProperties("spring.metrics.export") +@ConfigurationProperties(prefix = "spring.metrics.export") public class MetricExportProperties extends TriggerProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java index bf5547472c..23a81c1496 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java @@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Vedran Pavic * @since 1.2.0 */ -@ConfigurationProperties("spring.batch") +@ConfigurationProperties(prefix = "spring.batch") public class BatchProperties { private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/" diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java index 7bfcdabe85..0403d3f3ae 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java @@ -27,7 +27,7 @@ import org.springframework.http.MediaType; * @author Stephane Nicoll * @since 1.3.0 */ -@ConfigurationProperties("spring.data.rest") +@ConfigurationProperties(prefix = "spring.data.rest") public class RepositoryRestProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestProperties.java index 4830c9a4b7..dbfd9b9ee8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestProperties.java @@ -27,7 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.4.0 */ -@ConfigurationProperties("spring.elasticsearch.jest") +@ConfigurationProperties(prefix = "spring.elasticsearch.jest") public class JestProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java index 61ef267818..5521b19f97 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java @@ -26,7 +26,7 @@ import org.springframework.util.Assert; * @author Stephane Nicoll * @since 1.3.0 */ -@ConfigurationProperties("spring.hazelcast") +@ConfigurationProperties(prefix = "spring.hazelcast") public class HazelcastProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoProperties.java index 7ab0c521a6..0ab854367a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoProperties.java @@ -28,7 +28,7 @@ import org.springframework.core.io.Resource; * @author Stephane Nicoll * @since 1.4.0 */ -@ConfigurationProperties("spring.info") +@ConfigurationProperties(prefix = "spring.info") public class ProjectInfoProperties { private final Build build = new Build(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java index e94c6c0163..b4b8169f62 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java @@ -50,7 +50,7 @@ abstract class DataSourceConfiguration { static class Tomcat extends DataSourceConfiguration { @Bean - @ConfigurationProperties("spring.datasource.tomcat") + @ConfigurationProperties(prefix = "spring.datasource.tomcat") public org.apache.tomcat.jdbc.pool.DataSource dataSource( DataSourceProperties properties) { org.apache.tomcat.jdbc.pool.DataSource dataSource = createDataSource( @@ -75,7 +75,7 @@ abstract class DataSourceConfiguration { static class Hikari extends DataSourceConfiguration { @Bean - @ConfigurationProperties("spring.datasource.hikari") + @ConfigurationProperties(prefix = "spring.datasource.hikari") public HikariDataSource dataSource(DataSourceProperties properties) { return createDataSource(properties, HikariDataSource.class); } @@ -93,7 +93,7 @@ abstract class DataSourceConfiguration { static class Dbcp extends DataSourceConfiguration { @Bean - @ConfigurationProperties("spring.datasource.dbcp") + @ConfigurationProperties(prefix = "spring.datasource.dbcp") public org.apache.commons.dbcp.BasicDataSource dataSource( DataSourceProperties properties) { org.apache.commons.dbcp.BasicDataSource dataSource = createDataSource( @@ -118,7 +118,7 @@ abstract class DataSourceConfiguration { static class Dbcp2 extends DataSourceConfiguration { @Bean - @ConfigurationProperties("spring.datasource.dbcp2") + @ConfigurationProperties(prefix = "spring.datasource.dbcp2") public org.apache.commons.dbcp2.BasicDataSource dataSource( DataSourceProperties properties) { return createDataSource(properties, diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyProperties.java index 77e56b032e..c65e3d0277 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyProperties.java @@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.jersey") +@ConfigurationProperties(prefix = "spring.jersey") public class JerseyProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index c81534285e..69cb1b7b46 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -54,7 +54,7 @@ class ActiveMQConnectionFactoryConfiguration { @Bean(destroyMethod = "stop") @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true", matchIfMissing = false) - @ConfigurationProperties("spring.activemq.pool.configuration") + @ConfigurationProperties(prefix = "spring.activemq.pool.configuration") public PooledConnectionFactory pooledJmsConnectionFactory( ActiveMQProperties properties) { PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory( diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java index f34ee78759..4ba6a33c1d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.mobile.devicedelegatingviewresolver") +@ConfigurationProperties(prefix = "spring.mobile.devicedelegatingviewresolver") public class DeviceDelegatingViewResolverProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2ClientProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2ClientProperties.java index 5cbb857572..f1998a0fb1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2ClientProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2ClientProperties.java @@ -27,7 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.3.0 */ -@ConfigurationProperties("security.oauth2.client") +@ConfigurationProperties(prefix = "security.oauth2.client") public class OAuth2ClientProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/AuthorizationServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/AuthorizationServerProperties.java index c038ac41f7..564daca214 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/AuthorizationServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/AuthorizationServerProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Dave Syer * @since 1.3.0 */ -@ConfigurationProperties("security.oauth2.authorization") +@ConfigurationProperties(prefix = "security.oauth2.authorization") public class AuthorizationServerProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java index 4480b40de7..3ac33cdce8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java @@ -174,7 +174,7 @@ public class OAuth2AuthorizationServerConfiguration } @Bean - @ConfigurationProperties("security.oauth2.client") + @ConfigurationProperties(prefix = "security.oauth2.client") public BaseClientDetails oauth2ClientDetails() { BaseClientDetails details = new BaseClientDetails(); if (this.client.getClientId() == null) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ProtectedResourceDetailsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ProtectedResourceDetailsConfiguration.java index f2c5fbdf6c..3731c9a955 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ProtectedResourceDetailsConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ProtectedResourceDetailsConfiguration.java @@ -31,7 +31,7 @@ import org.springframework.security.oauth2.client.token.grant.code.Authorization class OAuth2ProtectedResourceDetailsConfiguration { @Bean - @ConfigurationProperties("security.oauth2.client") + @ConfigurationProperties(prefix = "security.oauth2.client") @Primary public AuthorizationCodeResourceDetails oauth2RemoteResource() { return new AuthorizationCodeResourceDetails(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java index 86866d662f..ba5ff1cf9e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java @@ -74,7 +74,7 @@ public class OAuth2RestOperationsConfiguration { protected static class SingletonScopedConfiguration { @Bean - @ConfigurationProperties("security.oauth2.client") + @ConfigurationProperties(prefix = "security.oauth2.client") @Primary public ClientCredentialsResourceDetails oauth2RemoteResource() { ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java index a53a19d7ae..18c2af2249 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Dave Syer * @since 1.3.0 */ -@ConfigurationProperties("security.oauth2.sso") +@ConfigurationProperties(prefix = "security.oauth2.sso") public class OAuth2SsoProperties { public static final String DEFAULT_LOGIN_PATH = "/login"; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerProperties.java index c53f5c60d0..c55ddd5de0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerProperties.java @@ -37,7 +37,7 @@ import org.springframework.validation.Validator; * @author Dave Syer * @since 1.3.0 */ -@ConfigurationProperties("security.oauth2.resource") +@ConfigurationProperties(prefix = "security.oauth2.resource") public class ResourceServerProperties implements Validator, BeanFactoryAware { @JsonIgnore diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java index fc83b3f595..5faead4c59 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java @@ -30,7 +30,7 @@ import org.springframework.session.hazelcast.HazelcastFlushMode; * @author Vedran Pavic * @since 1.4.0 */ -@ConfigurationProperties("spring.session") +@ConfigurationProperties(prefix = "spring.session") public class SessionProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookProperties.java index 5280fe4a26..17473b370c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.social.facebook") +@ConfigurationProperties(prefix = "spring.social.facebook") public class FacebookProperties extends SocialProperties { } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInProperties.java index c19ce5e065..d0df42a91a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.social.linkedin") +@ConfigurationProperties(prefix = "spring.social.linkedin") public class LinkedInProperties extends SocialProperties { } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterProperties.java index 6f14ace3b5..4c71e07018 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterProperties.java @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.social.twitter") +@ConfigurationProperties(prefix = "spring.social.twitter") public class TwitterProperties extends SocialProperties { } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java index e9c14c3a19..442c36d425 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java @@ -27,7 +27,7 @@ import org.springframework.util.MimeType; * @author Stephane Nicoll * @since 1.2.0 */ -@ConfigurationProperties("spring.thymeleaf") +@ConfigurationProperties(prefix = "spring.thymeleaf") public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8"); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java index 7273dd2e5d..9ff6e75f3a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionProperties.java @@ -27,7 +27,7 @@ import org.springframework.transaction.support.AbstractPlatformTransactionManage * @author Phillip Webb * @since 1.5.0 */ -@ConfigurationProperties("spring.transaction") +@ConfigurationProperties(prefix = "spring.transaction") public class TransactionProperties implements PlatformTransactionManagerCustomizer { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java index dbd3d54fef..ca2c99f5a2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java @@ -71,7 +71,7 @@ class BitronixJtaConfiguration { @Bean @ConditionalOnMissingBean - @ConfigurationProperties("spring.jta.bitronix.properties") + @ConfigurationProperties(prefix = "spring.jta.bitronix.properties") public bitronix.tm.Configuration bitronixConfiguration() { bitronix.tm.Configuration config = TransactionManagerServices.getConfiguration(); if (StringUtils.hasText(this.jtaProperties.getTransactionManagerId())) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java index c9a288022f..bb0a416bfe 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java @@ -33,7 +33,7 @@ import org.springframework.validation.DefaultMessageCodesResolver; * @author Eddú Meléndez * @since 1.1 */ -@ConfigurationProperties("spring.mvc") +@ConfigurationProperties(prefix = "spring.mvc") public class WebMvcProperties { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java index 978c32f5af..187b3d2512 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java @@ -31,7 +31,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.4.0 */ -@ConfigurationProperties("spring.webservices") +@ConfigurationProperties(prefix = "spring.webservices") public class WebServicesProperties { /** diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java index 55772c1402..e47fddeed0 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java @@ -56,7 +56,7 @@ public class RestDocsAutoConfiguration { } @Bean - @ConfigurationProperties("spring.test.restdocs") + @ConfigurationProperties(prefix = "spring.test.restdocs") public RestDocsMockMvcBuilderCustomizer restDocumentationConfigurer( MockMvcRestDocumentationConfigurer configurer, ObjectProvider resultHandler) { diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java index 6fbce1b698..f3d60753c0 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java @@ -74,7 +74,7 @@ public class MockMvcAutoConfiguration { } @Bean - @ConfigurationProperties("spring.test.mockmvc") + @ConfigurationProperties(prefix = "spring.test.mockmvc") public SpringBootMockMvcBuilderCustomizer springBootMockMvcBuilderCustomizer() { return new SpringBootMockMvcBuilderCustomizer(this.context); } diff --git a/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java b/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java index 1b7354b2c4..aab6d539cc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java +++ b/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java @@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 1.2.0 * @see #asProperties() */ -@ConfigurationProperties("spring.jta.atomikos.properties") +@ConfigurationProperties(prefix = "spring.jta.atomikos.properties") public class AtomikosProperties { private final Map values = new TreeMap(); From f42ebe428cfc570b98b5663122c1bc2470aad10b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2017 20:32:46 -0800 Subject: [PATCH 4/5] Remove JSR-330 configuration annotations Replace JSR-330 validation annotations from all internal `@ConfigurationProperties` classes with standard Asserts. Prior to this commit validation of our own configuration properties would only occur when the user happens to have compliant JSR-330 implementation on their classpath. See gh-7579 --- .../ManagementServerProperties.java | 9 +++++++-- .../boot/actuate/endpoint/AbstractEndpoint.java | 17 +++++++++++++---- .../actuate/endpoint/LiquibaseEndpoint.java | 6 ++++-- .../endpoint/mvc/AbstractMvcEndpoint.java | 13 +++++++++---- .../autoconfigure/flyway/FlywayProperties.java | 7 ++++--- .../autoconfigure/h2/H2ConsoleProperties.java | 13 +++++++++---- .../liquibase/LiquibaseProperties.java | 9 +++++++-- .../autoconfigure/web/ServerProperties.java | 9 +++++++-- .../webservices/WebServicesProperties.java | 13 +++++++++---- 9 files changed, 69 insertions(+), 27 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java index 6b87ecce63..af60c3602d 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java @@ -20,8 +20,8 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.List; +import javax.annotation.PostConstruct; import javax.servlet.http.HttpSession; -import javax.validation.constraints.NotNull; import org.springframework.boot.autoconfigure.security.SecurityPrerequisite; import org.springframework.boot.autoconfigure.security.SecurityProperties; @@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** @@ -78,7 +79,6 @@ public class ManagementServerProperties implements SecurityPrerequisite { /** * Management endpoint context-path. */ - @NotNull private String contextPath = ""; /** @@ -88,6 +88,11 @@ public class ManagementServerProperties implements SecurityPrerequisite { private final Security security = new Security(); + @PostConstruct + private void validate() { + Assert.notNull(this.contextPath, "ContextPath must not be null"); + } + /** * Returns the management port or {@code null} if the * {@link ServerProperties#getPort() server port} should be used. diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java index 0eb7d2d86a..5e0ff14a8e 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java @@ -16,11 +16,13 @@ package org.springframework.boot.actuate.endpoint; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import java.util.regex.Pattern; + +import javax.annotation.PostConstruct; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; +import org.springframework.util.Assert; /** * Abstract base for {@link Endpoint} implementations. @@ -31,14 +33,14 @@ import org.springframework.core.env.Environment; */ public abstract class AbstractEndpoint implements Endpoint, EnvironmentAware { + private static final Pattern ID_PATTERN = Pattern.compile("\\w+"); + private Environment environment; /** * Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped * to a URL (e.g. 'foo' is mapped to '/foo'). */ - @NotNull - @Pattern(regexp = "\\w+", message = "ID must only contains letters, numbers and '_'") private String id; private final boolean sensitiveDefault; @@ -53,6 +55,13 @@ public abstract class AbstractEndpoint implements Endpoint, EnvironmentAwa */ private Boolean enabled; + @PostConstruct + private void validate() { + Assert.notNull(this.id, "Id must not be null"); + Assert.isTrue(ID_PATTERN.matcher(this.id).matches(), + "ID must only contains letters, numbers and '_'"); + } + /** * Create a new sensitive endpoint instance. The endpoint will enabled flag will be * based on the spring {@link Environment} unless explicitly set. diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java index 99c4f64251..37fd90a99f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java @@ -62,9 +62,11 @@ public class LiquibaseEndpoint extends AbstractEndpoint> { for (Map.Entry entry : this.liquibases.entrySet()) { try { DataSource dataSource = entry.getValue().getDataSource(); - JdbcConnection connection = new JdbcConnection(dataSource.getConnection()); + JdbcConnection connection = new JdbcConnection( + dataSource.getConnection()); try { - Database database = factory.findCorrectDatabaseImplementation(connection); + Database database = factory + .findCorrectDatabaseImplementation(connection); reports.add(new LiquibaseReport(entry.getKey(), service.queryDatabaseChangeLogTable(database))); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java index bd1abcd6ee..329827d9ff 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java @@ -16,13 +16,13 @@ package org.springframework.boot.actuate.endpoint.mvc; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import javax.annotation.PostConstruct; import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.EndpointProperties; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; +import org.springframework.util.Assert; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** @@ -41,8 +41,6 @@ public abstract class AbstractMvcEndpoint extends WebMvcConfigurerAdapter /** * Endpoint URL path. */ - @NotNull - @Pattern(regexp = "/.*|^$", message = "Path must start with / or be empty") private String path; /** @@ -68,6 +66,13 @@ public abstract class AbstractMvcEndpoint extends WebMvcConfigurerAdapter this.enabled = enabled; } + @PostConstruct + private void validate() { + Assert.notNull(this.path, "Path must not be null"); + Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + "Path must start with / or be empty"); + } + @Override public void setEnvironment(Environment environment) { this.environment = environment; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java index d503f79e05..7fc6809a17 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java @@ -37,10 +37,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class FlywayProperties { /** - * Locations of migrations scripts. Can contain the special "{vendor}" placeholder - * to use vendor-specific locations. + * Locations of migrations scripts. Can contain the special "{vendor}" placeholder to + * use vendor-specific locations. */ - private List locations = new ArrayList(Collections.singletonList("db/migration")); + private List locations = new ArrayList( + Collections.singletonList("db/migration")); /** * Check that migration scripts location exists. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java index a4827c0be8..758d0bd029 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java @@ -16,10 +16,10 @@ package org.springframework.boot.autoconfigure.h2; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import javax.annotation.PostConstruct; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.Assert; /** * Configuration properties for H2's console. @@ -35,8 +35,6 @@ public class H2ConsoleProperties { /** * Path at which the console will be available. */ - @NotNull - @Pattern(regexp = "/[^?#]*", message = "Path must start with /") private String path = "/h2-console"; /** @@ -46,6 +44,13 @@ public class H2ConsoleProperties { private final Settings settings = new Settings(); + @PostConstruct + private void validate() { + Assert.notNull(this.path, "Path must not be null"); + Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + "Path must start with / or be empty"); + } + public String getPath() { return this.path; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java index 14a92ea920..42b5726647 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java @@ -19,11 +19,12 @@ package org.springframework.boot.autoconfigure.liquibase; import java.io.File; import java.util.Map; -import javax.validation.constraints.NotNull; +import javax.annotation.PostConstruct; import liquibase.integration.spring.SpringLiquibase; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.Assert; /** * Configuration properties to configure {@link SpringLiquibase}. @@ -37,7 +38,6 @@ public class LiquibaseProperties { /** * Change log configuration path. */ - @NotNull private String changeLog = "classpath:/db/changelog/db.changelog-master.yaml"; /** @@ -96,6 +96,11 @@ public class LiquibaseProperties { */ private File rollbackFile; + @PostConstruct + private void validate() { + Assert.notNull(this.changeLog, "ChangeLog must not be null"); + } + public String getChangeLog() { return this.changeLog; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index a7def07eed..98179cf681 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -26,11 +26,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.PostConstruct; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; -import javax.validation.constraints.NotNull; import io.undertow.Undertow.Builder; import io.undertow.UndertowOptions; @@ -74,6 +74,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.EnvironmentAware; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; +import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -122,7 +123,6 @@ public class ServerProperties /** * Path of the main dispatcher servlet. */ - @NotNull private String servletPath = "/"; /** @@ -176,6 +176,11 @@ public class ServerProperties private Environment environment; + @PostConstruct + private void validate() { + Assert.notNull(this.servletPath, "ServletPath must not be null"); + } + @Override public int getOrder() { return 0; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java index 187b3d2512..83220c0684 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java @@ -19,10 +19,10 @@ package org.springframework.boot.autoconfigure.webservices; import java.util.HashMap; import java.util.Map; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import javax.annotation.PostConstruct; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.Assert; /** * {@link ConfigurationProperties} for Spring Web Services. @@ -37,12 +37,17 @@ public class WebServicesProperties { /** * Path that serves as the base URI for the services. */ - @NotNull - @Pattern(regexp = "/[^?#]*", message = "Path must start with /") private String path = "/services"; private final Servlet servlet = new Servlet(); + @PostConstruct + private void validate() { + Assert.notNull(this.path, "Path must not be null"); + Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + "Path must start with / or be empty"); + } + public String getPath() { return this.path; } From 10dbf3c571258bcc788d4fd091aeb42b3c011da6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2017 20:29:31 -0800 Subject: [PATCH 5/5] Use `@Validated` as trigger for JSR-330 validation Update `ConfigurationPropertiesBindingPostProcessor` so that `@Validated` is expected to be used to trigger JSR-330 validation. Any existing configuration classes that use JSR-330 annotations but don't have `@Validated` will currently still be validated, but will now log a warning. This should give users a chance to add the requested annotations before the next Spring Boot release where we will use them as the exclusive signal that validation is required. Closes gh-7579 --- .../main/asciidoc/spring-boot-features.adoc | 10 ++-- .../spring-boot-sample-simple/pom.xml | 4 ++ .../simple/SampleConfigurationProperties.java | 39 ++++++++++++++++ .../src/main/resources/application.properties | 4 +- .../simple/SampleSimpleApplicationTests.java | 4 ++ .../src/test/resources/application.properties | 1 - .../bind/PropertiesConfigurationFactory.java | 7 +-- .../properties/ConfigurationProperties.java | 8 ++-- ...urationPropertiesBindingPostProcessor.java | 46 ++++++++++++++----- ...onPropertiesBindingPostProcessorTests.java | 2 + .../EnableConfigurationPropertiesTests.java | 37 +++++++++++++++ .../analyzer/BindFailureAnalyzerTests.java | 2 + 12 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/test/resources/application.properties diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 9684b2870c..c773a776b2 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1090,13 +1090,16 @@ only rely on custom converters qualified with `@ConfigurationPropertiesBinding`. [[boot-features-external-config-validation]] ==== @ConfigurationProperties Validation -Spring Boot will attempt to validate external configuration, by default using JSR-303 -(if it is on the classpath). You can simply add JSR-303 `javax.validation` constraint -annotations to your `@ConfigurationProperties` class: +Spring Boot will attempt to validate `@ConfigurationProperties` classes whenever they +annotated with Spring's `@Validated` annotation. You can use JSR-303 `javax.validation` +constraint annotations directly on your configuration class. Simply ensure that a +compliant JSR-303 implementation is on your classpath, then add constraint annotations to +your fields: [source,java,indent=0] ---- @ConfigurationProperties(prefix="foo") + @Validated public class FooProperties { @NotNull @@ -1114,6 +1117,7 @@ as `@Valid` to trigger its validation. For example, building upon the above [source,java,indent=0] ---- @ConfigurationProperties(prefix="connection") + @Validated public class FooProperties { @NotNull diff --git a/spring-boot-samples/spring-boot-sample-simple/pom.xml b/spring-boot-samples/spring-boot-sample-simple/pom.xml index 7fccbaab2d..9387a641ee 100644 --- a/spring-boot-samples/spring-boot-sample-simple/pom.xml +++ b/spring-boot-samples/spring-boot-sample-simple/pom.xml @@ -24,6 +24,10 @@ org.springframework.boot spring-boot-starter + + org.hibernate + hibernate-validator + org.springframework.boot diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java new file mode 100644 index 0000000000..566e9010c5 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java @@ -0,0 +1,39 @@ +/* + * 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. + * 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 sample.simple; + +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "sample") +public class SampleConfigurationProperties { + + @NotNull + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties index b04cdc39b5..9964fe3399 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties @@ -1 +1,3 @@ -name: Phil +name=Phil +sample.name=Andy + diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java index 057e0f761d..3591b21031 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java @@ -58,6 +58,10 @@ public class SampleSimpleApplicationTests { SampleSimpleApplication.main(new String[0]); String output = this.outputCapture.toString(); assertThat(output).contains("Hello Phil"); + assertThat(output).contains("The @ConfigurationProperties bean class " + + "sample.simple.SampleConfigurationProperties contains " + + "validation constraints but had not been annotated " + + "with @Validated"); } @Test diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/resources/application.properties b/spring-boot-samples/spring-boot-sample-simple/src/test/resources/application.properties deleted file mode 100644 index 4dfe84cedc..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -name: Phil \ No newline at end of file diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java index 13f305da05..eca9522251 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java @@ -267,8 +267,9 @@ public class PropertiesConfigurationFactory relaxedTargetNames); dataBinder.bind(propertyValues); if (this.validator != null) { - validate(dataBinder); + dataBinder.validate(); } + checkForBindingErrors(dataBinder); } private Iterable getRelaxedTargetNames() { @@ -338,8 +339,8 @@ public class PropertiesConfigurationFactory return this.target != null && Map.class.isAssignableFrom(this.target.getClass()); } - private void validate(RelaxedDataBinder dataBinder) throws BindException { - dataBinder.validate(); + private void checkForBindingErrors(RelaxedDataBinder dataBinder) + throws BindException { BindingResult errors = dataBinder.getBindingResult(); if (errors.hasErrors()) { logger.error("Properties configuration failed validation"); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java index f6734e8c54..b7a7447bde 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java @@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; +import org.springframework.validation.annotation.Validated; /** * Annotation for externalized configuration. Add this to a class definition or a @@ -80,9 +81,10 @@ public @interface ConfigurationProperties { boolean ignoreUnknownFields() default true; /** - * Flag to indicate that an exception should be raised if a Validator is available and - * validation fails. If it is set to false, validation errors will be swallowed. They - * will be logged, but not propagated to the caller. + * Flag to indicate that an exception should be raised if a Validator is available, + * the class is annotated with {@link Validated @Validated} and validation fails. If + * it is set to false, validation errors will be swallowed. They will be logged, but + * not propagated to the caller. * @return the flag value (default true) */ boolean exceptionIfInvalid() default true; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java index 3bf2c3d01e..d704eec7c7 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java @@ -45,6 +45,7 @@ import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.converter.Converter; @@ -61,6 +62,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.validation.Errors; import org.springframework.validation.Validator; +import org.springframework.validation.annotation.Validated; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; /** @@ -362,8 +364,8 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc return this.validator; } if (this.localValidator == null && isJsr303Present()) { - this.localValidator = new LocalValidatorFactory() - .run(this.applicationContext); + this.localValidator = new ValidatedLocalValidatorFactoryBean( + this.applicationContext); } return this.localValidator; } @@ -394,18 +396,38 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc } /** - * Factory to create JSR 303 LocalValidatorFactoryBean. Inner class to prevent class - * loader issues. + * {@link LocalValidatorFactoryBean} supports classes annotated with + * {@link Validated @Validated}. */ - private static class LocalValidatorFactory { + private static class ValidatedLocalValidatorFactoryBean + extends LocalValidatorFactoryBean { - public Validator run(ApplicationContext applicationContext) { - LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); - MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory(); - validator.setApplicationContext(applicationContext); - validator.setMessageInterpolator(interpolatorFactory.getObject()); - validator.afterPropertiesSet(); - return validator; + private static final Log logger = LogFactory + .getLog(ConfigurationPropertiesBindingPostProcessor.class); + + ValidatedLocalValidatorFactoryBean(ApplicationContext applicationContext) { + setApplicationContext(applicationContext); + setMessageInterpolator(new MessageInterpolatorFactory().getObject()); + afterPropertiesSet(); + } + + @Override + public boolean supports(Class type) { + if (!super.supports(type)) { + return false; + } + if (AnnotatedElementUtils.isAnnotated(type, Validated.class)) { + return true; + } + if (type.getPackage().getName().startsWith("org.springframework.boot")) { + return false; + } + if (getConstraintsForClass(type).isBeanConstrained()) { + logger.warn("The @ConfigurationProperties bean " + type + + " contains validation constraints but had not been annotated " + + "with @Validated."); + } + return true; } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java index 48c98d4509..b653723429 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java @@ -46,6 +46,7 @@ import org.springframework.validation.BindException; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; +import org.springframework.validation.annotation.Validated; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -456,6 +457,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests { } @ConfigurationProperties(prefix = "test") + @Validated public static class PropertyWithJSR303 extends PropertyWithoutJSR303 { @NotNull diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index 492e2f81a1..93c253c708 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -38,6 +38,7 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.stereotype.Component; import org.springframework.test.context.support.TestPropertySourceUtils; import org.springframework.validation.BindException; +import org.springframework.validation.annotation.Validated; import static org.assertj.core.api.Assertions.assertThat; @@ -172,6 +173,17 @@ public class EnableConfigurationPropertiesTests { this.context.refresh(); } + @Test + public void testNoExceptionOnValidationWithoutValidated() { + this.context.register(IgnoredIfInvalidButNotValidatedTestConfiguration.class); + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, + "name:foo"); + this.context.refresh(); + IgnoredIfInvalidButNotValidatedTestProperties bean = this.context + .getBean(IgnoredIfInvalidButNotValidatedTestProperties.class); + assertThat(bean.getDescription()).isNull(); + } + @Test public void testNoExceptionOnValidation() { this.context.register(NoExceptionIfInvalidTestConfiguration.class); @@ -432,6 +444,12 @@ public class EnableConfigurationPropertiesTests { } + @Configuration + @EnableConfigurationProperties(IgnoredIfInvalidButNotValidatedTestProperties.class) + protected static class IgnoredIfInvalidButNotValidatedTestConfiguration { + + } + @Configuration @EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class) protected static class NoExceptionIfInvalidTestConfiguration { @@ -658,6 +676,7 @@ public class EnableConfigurationPropertiesTests { } @ConfigurationProperties + @Validated protected static class ExceptionIfInvalidTestProperties extends TestProperties { @NotNull @@ -673,7 +692,25 @@ public class EnableConfigurationPropertiesTests { } + @ConfigurationProperties + protected static class IgnoredIfInvalidButNotValidatedTestProperties + extends TestProperties { + + @NotNull + private String description; + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + } + @ConfigurationProperties(exceptionIfInvalid = false) + @Validated protected static class NoExceptionIfInvalidTestProperties extends TestProperties { @NotNull diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java index 93a34e0cc8..66f0f0bca2 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.validation.annotation.Validated; import static org.assertj.core.api.Assertions.assertThat; @@ -90,6 +91,7 @@ public class BindFailureAnalyzerTests { } @ConfigurationProperties("test.foo") + @Validated static class ValidationFailureProperties { @NotNull