From 952224ef567a5026c766265656714db67f144d9e Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 29 Nov 2017 08:21:59 +0900 Subject: [PATCH] Polish Closes gh-11193 --- ...ndpointManagementContextConfiguration.java | 1 - .../MetricsAutoConfigurationTests.java | 2 +- .../session/SessionAutoConfiguration.java | 6 +-- ...ervletWebServerFactoryCustomizerTests.java | 40 +++++++++---------- .../asciidoc/production-ready-features.adoc | 2 +- ...onConfigReactiveWebApplicationContext.java | 3 +- ...igReactiveWebServerApplicationContext.java | 11 ++--- ...figServletWebServerApplicationContext.java | 4 +- ...igurationPropertiesBinderBuilderTests.java | 4 +- 9 files changed, 36 insertions(+), 37 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java index 7ef32c6707..c38b0d69fa 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java @@ -41,7 +41,6 @@ import org.springframework.context.annotation.Configuration; * * @author Andy Wilkinson * @author Phillip Webb - * @since 2.0.0 */ @Configuration @ConditionalOnWebApplication(type = Type.SERVLET) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java index 89a1575f9d..f0670d2e1f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java @@ -86,7 +86,7 @@ public class MetricsAutoConfigurationTests { .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("custom.name.max.connections") + assertThat(registry.find("data.source.max.connections") .tags("name", "dataSource").meter()).isNotPresent(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index 6b33a096c1..dbaee1bfc9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -153,7 +153,7 @@ public class SessionAutoConfiguration { * Base class for beans used to validate that only one supported implementation is * available in the classpath when the store-type property is not set. */ - static class AbstractSessionRepositoryImplementationValidator { + static abstract class AbstractSessionRepositoryImplementationValidator { private final List candidates; @@ -233,7 +233,7 @@ public class SessionAutoConfiguration { /** * Base class for validating that a (reactive) session repository bean exists. */ - static class AbstractSessionRepositoryValidator { + static abstract class AbstractSessionRepositoryValidator { private final SessionProperties sessionProperties; @@ -276,7 +276,7 @@ public class SessionAutoConfiguration { } /** - * Bean used to validate that a {@link SessionRepository} exists and provide a + * Bean used to validate that a {@link ReactiveSessionRepository} exists and provide a * meaningful message if that's not the case. */ static class ReactiveSessionRepositoryValidator diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizerTests.java index 548e193493..5b3328ffba 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizerTests.java @@ -350,14 +350,14 @@ public class DefaultServletWebServerFactoryCustomizerTests { bindProperties(map); TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); this.customizer.customize(factory); - TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer(); - embeddedFactory.start(); + TomcatWebServer server = (TomcatWebServer) factory.getWebServer(); + server.start(); try { - assertThat(((AbstractProtocol) embeddedFactory.getTomcat().getConnector() + assertThat(((AbstractProtocol) server.getTomcat().getConnector() .getProtocolHandler()).getAcceptCount()).isEqualTo(10); } finally { - embeddedFactory.stop(); + server.stop(); } } @@ -368,14 +368,14 @@ public class DefaultServletWebServerFactoryCustomizerTests { bindProperties(map); TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); this.customizer.customize(factory); - TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer(); - embeddedFactory.start(); + TomcatWebServer server = (TomcatWebServer) factory.getWebServer(); + server.start(); try { - assertThat(((AbstractProtocol) embeddedFactory.getTomcat().getConnector() + assertThat(((AbstractProtocol) server.getTomcat().getConnector() .getProtocolHandler()).getMaxConnections()).isEqualTo(5); } finally { - embeddedFactory.stop(); + server.stop(); } } @@ -386,14 +386,14 @@ public class DefaultServletWebServerFactoryCustomizerTests { bindProperties(map); TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); this.customizer.customize(factory); - TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer(); - embeddedFactory.start(); + TomcatWebServer server = (TomcatWebServer) factory.getWebServer(); + server.start(); try { - assertThat(embeddedFactory.getTomcat().getConnector().getMaxPostSize()) + assertThat(server.getTomcat().getConnector().getMaxPostSize()) .isEqualTo(10000); } finally { - embeddedFactory.stop(); + server.stop(); } } @@ -404,14 +404,14 @@ public class DefaultServletWebServerFactoryCustomizerTests { bindProperties(map); TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); this.customizer.customize(factory); - TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer(); - embeddedFactory.start(); + TomcatWebServer server = (TomcatWebServer) factory.getWebServer(); + server.start(); try { - assertThat(embeddedFactory.getTomcat().getConnector().getMaxPostSize()) + assertThat(server.getTomcat().getConnector().getMaxPostSize()) .isEqualTo(-1); } finally { - embeddedFactory.stop(); + server.stop(); } } @@ -611,15 +611,15 @@ public class DefaultServletWebServerFactoryCustomizerTests { bindProperties(map); TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); this.customizer.customize(factory); - TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer(); - embeddedFactory.start(); + TomcatWebServer server = (TomcatWebServer) factory.getWebServer(); + server.start(); try { - Tomcat tomcat = embeddedFactory.getTomcat(); + Tomcat tomcat = server.getTomcat(); Context context = (Context) tomcat.getHost().findChildren()[0]; assertThat(context.getResources().getCacheTtl()).isEqualTo(10000L); } finally { - embeddedFactory.stop(); + server.stop(); } } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 7f8ccc5238..2509ab135b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1015,7 +1015,7 @@ following information: [[production-ready-metrics-jdbc]] === DataSource metrics -Auto-configuration will enable the instrumentation of all available `DataSources` with a +Auto-configuration will enable the instrumentation of all available ``DataSource``s with a metric named `data.source`. Data source instrumentation results in gauges representing the currently active, maximum allowed, and minimum allowed connections in the pool. Each of these gauges has a name which is prefixed by `data.source` by default. The prefix can diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java index 656e69684e..09f37b8aa6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; /** * {@link ConfigurableReactiveWebApplicationContext} that accepts annotated classes as * input - in particular - * {@link org.springframework.context.annotation.Configuration @Configuration} -annotated + * {@link org.springframework.context.annotation.Configuration @Configuration}-annotated * classes, but also plain {@link Component @Component} classes and JSR-330 compliant * classes using {@code javax.inject} annotations. Allows for registering classes one by * one (specifying class names as config location) as well as for classpath scanning @@ -311,7 +311,6 @@ public class AnnotationConfigReactiveWebApplicationContext * with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet. * @param beanFactory the bean factory to load bean definitions into * @return the class path bean definition scanner - * @since 4.1.9 * @see #getEnvironment() * @see #getBeanNameGenerator() * @see #getScopeMetadataResolver() diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java index ccc21547f3..b8f38f3df7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java @@ -28,11 +28,12 @@ import org.springframework.context.annotation.ScopeMetadataResolver; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.stereotype.Component; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * {@link ReactiveWebServerApplicationContext} that accepts annotated classes as input - * in particular - * {@link org.springframework.context.annotation.Configuration @Configuration} -annotated + * {@link org.springframework.context.annotation.Configuration @Configuration}-annotated * classes, but also plain {@link Component @Component} classes and JSR-330 compliant * classes using {@code javax.inject} annotations. Allows for registering classes one by * one (specifying class names as config location) as well as for classpath scanning @@ -124,8 +125,8 @@ public class AnnotationConfigReactiveWebServerApplicationContext /** * Provide a custom {@link BeanNameGenerator} for use with - * {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner} - * , if any. + * {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner}, + * if any. *

* Default is * {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}. @@ -197,10 +198,10 @@ public class AnnotationConfigReactiveWebServerApplicationContext @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.postProcessBeanFactory(beanFactory); - if (this.basePackages != null && this.basePackages.length > 0) { + if (!ObjectUtils.isEmpty(this.basePackages)) { this.scanner.scan(this.basePackages); } - if (this.annotatedClasses != null && this.annotatedClasses.length > 0) { + if (!ObjectUtils.isEmpty(this.annotatedClasses)) { this.reader.register(this.annotatedClasses); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java index fafcd72775..0d7443792a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java @@ -122,8 +122,8 @@ public class AnnotationConfigServletWebServerApplicationContext /** * Provide a custom {@link BeanNameGenerator} for use with - * {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner} - * , if any. + * {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner}, + * if any. *

* Default is * {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilderTests.java index abc0216958..50f27ab657 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilderTests.java @@ -101,12 +101,12 @@ public class ConfigurationPropertiesBinderBuilderTests { @Test public void detectDefaultValidator() { - this.applicationContext.registerSingleton("configurationPropertiesValidator", + this.applicationContext.registerSingleton(ConfigurationPropertiesBindingPostProcessor.VALIDATOR_BEAN_NAME, LocalValidatorFactoryBean.class); ConfigurationPropertiesBinder binder = this.builder .withEnvironment(this.environment).build(); assertThat(ReflectionTestUtils.getField(binder, "validator")).isSameAs( - this.applicationContext.getBean("configurationPropertiesValidator")); + this.applicationContext.getBean(ConfigurationPropertiesBindingPostProcessor.VALIDATOR_BEAN_NAME)); } @Test