From 891dd5a0f6c23d11fb876bcceda79690e7c8efa9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 3 Aug 2015 11:03:32 -0700 Subject: [PATCH] Polish --- .../ConditionalOnEnablednHealthIndicator.java | 6 +- .../actuate/autoconfigure/LinksEnhancer.java | 1 + .../OnEnabledHealthIndicatorCondition.java | 29 ++++---- .../util/SimpleInMemoryRepository.java | 8 +-- ...HealthIndicatorAutoConfigurationTests.java | 9 +-- .../JolokiaAutoConfigurationTests.java | 2 + .../autoconfigure/amqp/RabbitProperties.java | 4 +- .../autoconfigure/jdbc/DatabaseDriver.java | 3 +- .../boot/autoconfigure/jms/JmsProperties.java | 25 +++---- .../resource/ResourceServerProperties.java | 2 +- .../thymeleaf/ThymeleafProperties.java | 8 +-- .../amqp/RabbitAutoConfigurationTests.java | 7 +- .../JacksonAutoConfigurationTests.java | 6 +- .../jms/JmsAutoConfigurationTests.java | 10 +-- .../oauth2/OAuth2AutoConfigurationTests.java | 26 ++++---- .../BasicErrorControllerIntegrationTests.java | 1 + spring-boot-docs/src/main/asciidoc/howto.adoc | 1 - .../main/asciidoc/spring-boot-features.adoc | 1 - .../pom.xml | 2 - .../propertyvalidation/SampleProperties.java | 5 +- .../SamplePropertiesValidator.java | 5 +- .../SamplePropertyValidationApplication.java | 4 +- ...plePropertyValidationApplicationTests.java | 31 ++++----- .../boot/loader/LaunchedURLClassLoader.java | 66 +++++++++++-------- .../boot/bind/RelaxedDataBinderTests.java | 6 +- 25 files changed, 139 insertions(+), 129 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnEnablednHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnEnablednHealthIndicator.java index 9fc81792ca8..284886de6ab 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnEnablednHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ConditionalOnEnablednHealthIndicator.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -33,9 +34,10 @@ import org.springframework.context.annotation.Conditional; * @author Stephane Nicoll * @since 1.3.0 */ -@Conditional(OnEnabledHealthIndicatorCondition.class) @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Documented +@Conditional(OnEnabledHealthIndicatorCondition.class) public @interface ConditionalOnEnablednHealthIndicator { /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/LinksEnhancer.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/LinksEnhancer.java index 97fdaf9ff8f..c37c701bb64 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/LinksEnhancer.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/LinksEnhancer.java @@ -66,4 +66,5 @@ class LinksEnhancer { resource.add(linkTo(type).slash(fullPath).withRel(rel)); } } + } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEnabledHealthIndicatorCondition.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEnabledHealthIndicatorCondition.java index 8be076a6899..2dba841ca68 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEnabledHealthIndicatorCondition.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEnabledHealthIndicatorCondition.java @@ -28,37 +28,38 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * {@link Condition} that checks if a health indicator is enabled. * * @author Stephane Nicoll - * @since 1.3.0 */ class OnEnabledHealthIndicatorCondition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata - .getAnnotationAttributes(ConditionalOnEnablednHealthIndicator.class.getName())); + private static final String ANNOTATION_CLASS = ConditionalOnEnablednHealthIndicator.class + .getName(); + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, + AnnotatedTypeMetadata metadata) { + AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata + .getAnnotationAttributes(ANNOTATION_CLASS)); String endpointName = annotationAttributes.getString("value"); - ConditionOutcome outcome = determineHealthIndicatorOutcome(endpointName, context); + ConditionOutcome outcome = getHealthIndicatorOutcome(context, endpointName); if (outcome != null) { return outcome; } - return determineDefaultIndicatorsOutcome(context); + return getDefaultIndicatorsOutcome(context); } - private ConditionOutcome determineHealthIndicatorOutcome(String endpointName, - ConditionContext context) { + private ConditionOutcome getHealthIndicatorOutcome(ConditionContext context, + String endpointName) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( context.getEnvironment(), "management.health." + endpointName + "."); if (resolver.containsProperty("enabled")) { - boolean match = resolver.getProperty("enabled", Boolean.class, - true); - return new ConditionOutcome(match, "The health indicator " + endpointName + - " is " + (match ? "enabled" : "disabled")); + boolean match = resolver.getProperty("enabled", Boolean.class, true); + return new ConditionOutcome(match, "The health indicator " + endpointName + + " is " + (match ? "enabled" : "disabled")); } return null; } - private ConditionOutcome determineDefaultIndicatorsOutcome(ConditionContext context) { + private ConditionOutcome getDefaultIndicatorsOutcome(ConditionContext context) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( context.getEnvironment(), "management.health.defaults."); boolean match = Boolean.valueOf(resolver.getProperty("enabled", "true")); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java index f8a8eaa4ab0..3a0ea79556b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java @@ -36,10 +36,6 @@ public class SimpleInMemoryRepository { private final ConcurrentMap locks = new ConcurrentReferenceHashMap(); - public interface Callback { - T modify(T current); - } - public T update(String name, Callback callback) { Object lock = this.locks.putIfAbsent(name, new Object()); if (lock == null) { @@ -101,4 +97,8 @@ public class SimpleInMemoryRepository { return this.values; } + public interface Callback { + T modify(T current); + } + } 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 52fd7bf9182..7695950ab91 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 @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure; import java.util.Map; + import javax.sql.DataSource; import org.junit.After; @@ -105,16 +106,15 @@ public class HealthIndicatorAutoConfigurationTests { @Test public void defaultHealthIndicatorsDisabledWithCustomOne() { this.context.register(CustomHealthIndicator.class, - HealthIndicatorAutoConfiguration.class, - ManagementServerProperties.class); + HealthIndicatorAutoConfiguration.class, ManagementServerProperties.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.defaults.enabled:false"); this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); - assertSame(this.context.getBean("customHealthIndicator"), beans.values(). - iterator().next()); + assertSame(this.context.getBean("customHealthIndicator"), beans.values() + .iterator().next()); } @Test @@ -445,6 +445,7 @@ public class HealthIndicatorAutoConfigurationTests { } }; } + } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index d6d227fc90e..bd0f7c1949a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -135,11 +135,13 @@ public class JolokiaAutoConfigurationTests { @Configuration protected static class EndpointsConfig extends Config { + @Bean public EndpointHandlerMapping endpointHandlerMapping( Collection endpoints) { return new EndpointHandlerMapping(endpoints); } + } @Configuration diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 15cf5ca047e..06b8d587085 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -306,7 +306,7 @@ public class RabbitProperties { private Integer maxConcurrency; /** - * Number of messages to be handled in a single request. It should be greater than + * Number of messages to be handled in a single request. It should be greater than * or equal to the transaction size (if used). */ private Integer prefetch; @@ -318,7 +318,7 @@ public class RabbitProperties { private Integer transactionSize; public boolean isAutoStartup() { - return autoStartup; + return this.autoStartup; } public void setAutoStartup(boolean autoStartup) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DatabaseDriver.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DatabaseDriver.java index 1897ad3116c..c071c75eec1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DatabaseDriver.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DatabaseDriver.java @@ -86,7 +86,8 @@ enum DatabaseDriver { /** * SQL Server */ - SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource"); + SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", + "com.microsoft.sqlserver.jdbc.SQLServerXADataSource"); private final String driverClassName; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java index 329de93fac2..fd252093080 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java @@ -58,7 +58,7 @@ public class JmsProperties { } public Listener getListener() { - return listener; + return this.listener; } public static class Listener { @@ -69,8 +69,8 @@ public class JmsProperties { private boolean autoStartup = true; /** - * Acknowledge mode of the container. By default, the listener is - * transacted with automatic acknowledgment. + * Acknowledge mode of the container. By default, the listener is transacted with + * automatic acknowledgment. */ private AcknowledgeMode acknowledgeMode; @@ -85,7 +85,7 @@ public class JmsProperties { private Integer maxConcurrency; public boolean isAutoStartup() { - return autoStartup; + return this.autoStartup; } public void setAutoStartup(boolean autoStartup) { @@ -93,7 +93,7 @@ public class JmsProperties { } public AcknowledgeMode getAcknowledgeMode() { - return acknowledgeMode; + return this.acknowledgeMode; } public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { @@ -120,16 +120,17 @@ public class JmsProperties { if (this.concurrency == null) { return (this.maxConcurrency != null ? "1-" + this.maxConcurrency : null); } - return (this.maxConcurrency != null ? this.concurrency + "-" + - this.maxConcurrency : String.valueOf(this.concurrency)); + return (this.maxConcurrency != null ? this.concurrency + "-" + + this.maxConcurrency : String.valueOf(this.concurrency)); } } /** * Translate the acknowledge modes defined on the {@link javax.jms.Session}. * - *

{@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take - * care of this already via a call to {@code setSessionTransacted}. + *

+ * {@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take care of this + * already via a call to {@code setSessionTransacted}. */ public enum AcknowledgeMode { @@ -140,8 +141,8 @@ public class JmsProperties { AUTO(1), /** - * Messages are acknowledged once the message listener implementation has - * called {@link javax.jms.Message#acknowledge()}. This mode gives the application + * Messages are acknowledged once the message listener implementation has called + * {@link javax.jms.Message#acknowledge()}. This mode gives the application * (rather than the JMS provider) complete control over message acknowledgement. */ CLIENT(2), @@ -160,7 +161,7 @@ public class JmsProperties { } public int getMode() { - return mode; + return this.mode; } } 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 97045d711b8..fa2b7d7dd5b 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 @@ -244,7 +244,7 @@ public class ResourceServerProperties implements Validator, BeanFactoryAware { } if (ResourceServerProperties.this.tokenInfoUri != null && ResourceServerProperties.this.tokenInfoUri - .endsWith("/check_token")) { + .endsWith("/check_token")) { return ResourceServerProperties.this.userInfoUri.replace("/check_token", "/token_key"); } 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 2e2fdcff7d7..3a58ef56d18 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 @@ -74,9 +74,9 @@ public class ThymeleafProperties { private boolean cache = true; /** - * Order of the template resolver in the chain. By default, the template resolver - * is first in the chain. Order start at 1 and should only be set if you have - * defined additional "TemplateResolver" beans. + * Order of the template resolver in the chain. By default, the template resolver is + * first in the chain. Order start at 1 and should only be set if you have defined + * additional "TemplateResolver" beans. */ private Integer templateResolverOrder; @@ -160,7 +160,7 @@ public class ThymeleafProperties { } public Integer getTemplateResolverOrder() { - return templateResolverOrder; + return this.templateResolverOrder; } public void setTemplateResolverOrder(Integer templateResolverOrder) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index 62c0fa84b70..28ede678837 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -23,7 +23,6 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.rabbit.annotation.EnableRabbit; @@ -189,8 +188,7 @@ public class RabbitAutoConfigurationTests { @Test public void testRabbitListenerContainerFactoryWithCustomSettings() { - load(TestConfiguration.class, - "spring.rabbitmq.listener.autoStartup:false", + load(TestConfiguration.class, "spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.maxConcurrency:10", @@ -201,8 +199,7 @@ public class RabbitAutoConfigurationTests { SimpleRabbitListenerContainerFactory.class); DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory); assertEquals(false, dfa.getPropertyValue("autoStartup")); - assertEquals(AcknowledgeMode.MANUAL, - dfa.getPropertyValue("acknowledgeMode")); + assertEquals(AcknowledgeMode.MANUAL, dfa.getPropertyValue("acknowledgeMode")); assertEquals(5, dfa.getPropertyValue("concurrentConsumers")); assertEquals(10, dfa.getPropertyValue("maxConcurrentConsumers")); assertEquals(40, dfa.getPropertyValue("prefetchCount")); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index 9158f85e7f6..59866697425 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -76,7 +76,7 @@ import static org.mockito.Mockito.mock; */ public class JacksonAutoConfigurationTests { - AnnotationConfigApplicationContext context; + private AnnotationConfigApplicationContext context; @Before public void setUp() { @@ -411,8 +411,8 @@ public class JacksonAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.date-format:zzzz"); this.context.refresh(); - ObjectMapper objectMapper = this.context - .getBean(Jackson2ObjectMapperBuilder.class).build(); + ObjectMapper objectMapper = this.context.getBean( + Jackson2ObjectMapperBuilder.class).build(); DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC); assertEquals("\"Koordinierte Universalzeit\"", diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index cecd2bc7793..fd13a0e5d72 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -146,8 +146,7 @@ public class JmsAutoConfigurationTests { @Test public void testJmsListenerContainerFactoryWithCustomSettings() { - load(EnableJmsConfiguration.class, - "spring.jms.listener.autoStartup=false", + load(EnableJmsConfiguration.class, "spring.jms.listener.autoStartup=false", "spring.jms.listener.acknowledgeMode=client", "spring.jms.listener.concurrency=2", "spring.jms.listener.maxConcurrency=10"); @@ -155,10 +154,11 @@ public class JmsAutoConfigurationTests { .getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class); assertEquals(DefaultJmsListenerContainerFactory.class, jmsListenerContainerFactory.getClass()); - DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) - jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class)); + DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory) + .createListenerContainer(mock(JmsListenerEndpoint.class)); assertEquals(false, listenerContainer.isAutoStartup()); - assertEquals(Session.CLIENT_ACKNOWLEDGE, listenerContainer.getSessionAcknowledgeMode()); + assertEquals(Session.CLIENT_ACKNOWLEDGE, + listenerContainer.getSessionAcknowledgeMode()); assertEquals(2, listenerContainer.getConcurrentConsumers()); assertEquals(10, listenerContainer.getMaxConcurrentConsumers()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java index f4d0100937a..5e845e8da25 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java @@ -16,9 +16,6 @@ package org.springframework.boot.autoconfigure.security.oauth2; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; - import java.net.URI; import java.util.Arrays; import java.util.List; @@ -94,6 +91,9 @@ import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.JsonNode; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + /** * Verify Spring Security OAuth2 auto-configuration secures end points properly, accepts * environmental overrides, and also backs off in the presence of other @@ -358,9 +358,9 @@ public class OAuth2AutoConfigurationTests { @Configuration @Import({ UseFreePortEmbeddedContainerConfiguration.class, - SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class, - DispatcherServletAutoConfiguration.class, OAuth2AutoConfiguration.class, - WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) + SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class, + DispatcherServletAutoConfiguration.class, OAuth2AutoConfiguration.class, + WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) protected static class MinimalSecureWebApplication { } @@ -396,7 +396,7 @@ public class OAuth2AutoConfigurationTests { @EnableResourceServer @EnableGlobalMethodSecurity(prePostEnabled = true) protected static class AuthorizationAndResourceServerConfiguration extends - TestSecurityConfiguration { + TestSecurityConfiguration { } @@ -419,7 +419,7 @@ public class OAuth2AutoConfigurationTests { @Configuration @EnableAuthorizationServer protected static class AuthorizationServerConfiguration extends - TestSecurityConfiguration { + TestSecurityConfiguration { } @@ -474,7 +474,7 @@ public class OAuth2AutoConfigurationTests { @Override public void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and() - .csrf().disable(); + .csrf().disable(); } } @@ -482,7 +482,7 @@ public class OAuth2AutoConfigurationTests { @Configuration @EnableAuthorizationServer protected static class CustomAuthorizationServer extends - AuthorizationServerConfigurerAdapter { + AuthorizationServerConfigurerAdapter { @Autowired private AuthenticationManager authenticationManager; @@ -502,9 +502,9 @@ public class OAuth2AutoConfigurationTests { @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory().withClient("client").secret("secret") - .resourceIds("resource-id").authorizedGrantTypes("password") - .authorities("USER").scopes("read") - .redirectUris("http://localhost:8080"); + .resourceIds("resource-id").authorizedGrantTypes("password") + .authorities("USER").scopes("read") + .redirectUris("http://localhost:8080"); } @Override diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index 55b1e193287..01fcf6225ac 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -181,6 +181,7 @@ public class BasicErrorControllerIntegrationTests { public NoReasonExpectedException(String message) { super(message); } + } } diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index f7bbe81e3ab..c7efe9e8322 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1476,7 +1476,6 @@ respectively. [[howto-use-exposing-spring-data-repositories-rest-endpoint]] === Expose Spring Data repositories as REST endpoint - Spring Data REST can expose the `Repository` implementations as REST endpoints for you as long as Spring MVC has been enabled for the application. 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 1292868dcb1..4e2dfd94946 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -781,7 +781,6 @@ annotations to your `@ConfigurationProperties` class: } ---- - In order to validate values of nested properties, you must annotate the associated field as `@Valid` to trigger its validation. For example, building upon the above `ConnectionSettings` example: diff --git a/spring-boot-samples/spring-boot-sample-property-validation/pom.xml b/spring-boot-samples/spring-boot-sample-property-validation/pom.xml index d67b931ae08..8b911dfa1b4 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/pom.xml +++ b/spring-boot-samples/spring-boot-sample-property-validation/pom.xml @@ -23,13 +23,11 @@ org.springframework.boot spring-boot-starter - org.springframework.boot spring-boot-configuration-processor true - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java index 0f79a28ecea..e990edf3943 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java @@ -34,7 +34,7 @@ public class SampleProperties { private Integer port = 8080; public String getHost() { - return host; + return this.host; } public void setHost(String host) { @@ -42,10 +42,11 @@ public class SampleProperties { } public Integer getPort() { - return port; + return this.port; } public void setPort(Integer port) { this.port = port; } + } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java index 8e4feb9e417..e0346267730 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java @@ -35,10 +35,9 @@ public class SamplePropertiesValidator implements Validator { public void validate(Object o, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "host", "host.empty"); ValidationUtils.rejectIfEmpty(errors, "port", "port.empty"); - SampleProperties properties = (SampleProperties) o; - if (properties.getHost() != null && - !pattern.matcher(properties.getHost()).matches()) { + if (properties.getHost() != null + && !this.pattern.matcher(properties.getHost()).matches()) { errors.rejectValue("host", "Invalid host"); } } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java index 44e061af470..478cf4d8869 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java @@ -52,8 +52,8 @@ public class SamplePropertyValidationApplication { } public static void main(String[] args) throws Exception { - new SpringApplicationBuilder(SamplePropertyValidationApplication.class) - .profiles("app").run(args); + new SpringApplicationBuilder(SamplePropertyValidationApplication.class).profiles( + "app").run(args); } } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java index b822fc6aade..79c62eef570 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java @@ -20,7 +20,6 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.test.EnvironmentTestUtils; @@ -43,16 +42,15 @@ public class SamplePropertyValidationApplicationTests { @After public void closeContext() { - context.close(); + this.context.close(); } @Test public void bindValidProperties() { this.context.register(SamplePropertyValidationApplication.class); - EnvironmentTestUtils.addEnvironment(this.context, - "sample.host:192.168.0.1", "sample.port:9090"); + EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1", + "sample.port:9090"); this.context.refresh(); - SampleProperties properties = this.context.getBean(SampleProperties.class); assertEquals("192.168.0.1", properties.getHost()); assertEquals(Integer.valueOf(9090), properties.getPort()); @@ -61,32 +59,29 @@ public class SamplePropertyValidationApplicationTests { @Test public void bindInvalidHost() { this.context.register(SamplePropertyValidationApplication.class); - EnvironmentTestUtils.addEnvironment(this.context, - "sample.host:xxxxxx", "sample.port:9090"); - - thrown.expect(BeanCreationException.class); - thrown.expectMessage("xxxxxx"); + EnvironmentTestUtils.addEnvironment(this.context, "sample.host:xxxxxx", + "sample.port:9090"); + this.thrown.expect(BeanCreationException.class); + this.thrown.expectMessage("xxxxxx"); this.context.refresh(); } @Test public void bindNullHost() { this.context.register(SamplePropertyValidationApplication.class); - - thrown.expect(BeanCreationException.class); - thrown.expectMessage("null"); - thrown.expectMessage("host"); + this.thrown.expect(BeanCreationException.class); + this.thrown.expectMessage("null"); + this.thrown.expectMessage("host"); this.context.refresh(); } @Test public void validatorOnlyCalledOnSupportedClass() { this.context.register(SamplePropertyValidationApplication.class); - this.context.register(ServerProperties.class); // our validator will not apply here - EnvironmentTestUtils.addEnvironment(this.context, - "sample.host:192.168.0.1", "sample.port:9090"); + this.context.register(ServerProperties.class); // our validator will not apply + EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1", + "sample.port:9090"); this.context.refresh(); - SampleProperties properties = this.context.getBean(SampleProperties.class); assertEquals("192.168.0.1", properties.getHost()); assertEquals(Integer.valueOf(9090), properties.getPort()); diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java index 0dd12281fff..52083c4ff4a 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java @@ -101,33 +101,8 @@ public class LaunchedURLClassLoader extends URLClassLoader { if (this.rootClassLoader == null) { return findResources(name); } - - final Enumeration rootResources = this.rootClassLoader.getResources(name); - final Enumeration localResources = findResources(name); - - return new Enumeration() { - - @Override - public boolean hasMoreElements() { - try { - Handler.setUseFastConnectionExceptions(true); - return rootResources.hasMoreElements() - || localResources.hasMoreElements(); - } - finally { - Handler.setUseFastConnectionExceptions(false); - } - } - - @Override - public URL nextElement() { - if (rootResources.hasMoreElements()) { - return rootResources.nextElement(); - } - return localResources.nextElement(); - } - - }; + return new ResourceEnumeration(this.rootClassLoader.getResources(name), + findResources(name)); } /** @@ -267,4 +242,41 @@ public class LaunchedURLClassLoader extends URLClassLoader { } + /** + * {@link Enumeration} implementation used for {@code getResources()}. + */ + private static class ResourceEnumeration implements Enumeration { + + private final Enumeration rootResources; + + private final Enumeration localResources; + + public ResourceEnumeration(Enumeration rootResources, + Enumeration localResources) { + this.rootResources = rootResources; + this.localResources = localResources; + } + + @Override + public boolean hasMoreElements() { + try { + Handler.setUseFastConnectionExceptions(true); + return this.rootResources.hasMoreElements() + || this.localResources.hasMoreElements(); + } + finally { + Handler.setUseFastConnectionExceptions(false); + } + } + + @Override + public URL nextElement() { + if (this.rootResources.hasMoreElements()) { + return this.rootResources.nextElement(); + } + return this.localResources.nextElement(); + } + + }; + } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java index 00bc24bad71..c819db77b88 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java @@ -355,11 +355,11 @@ public class RelaxedDataBinderTests { bind(target, "nested.foo: bar.key\n" + "nested[bar.key].spam: bucket\n" + "nested[bar.key].value: 123\nnested[bar.key].foo: crap"); assertEquals(2, target.getNested().size()); - Map nestedMap = (Map) target.getNested().get("bar.key"); + Map nestedMap = (Map) target.getNested().get( + "bar.key"); assertNotNull("nested map should be registered with 'bar.key'", nestedMap); assertEquals(3, nestedMap.size()); - assertEquals("123", - nestedMap.get("value")); + assertEquals("123", nestedMap.get("value")); assertEquals("bar.key", target.getNested().get("foo")); assertFalse(target.getNested().containsValue(target.getNested())); }