From d0a252181be4bac3bd0134a0fc2a3f38d27b05c8 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 13 Sep 2018 02:25:20 +0900 Subject: [PATCH] Polish Closes gh-14449 --- .../BackgroundPreinitializer.java | 2 +- .../autoconfigure/http/HttpProperties.java | 6 +-- ...fkaListenerContainerFactoryConfigurer.java | 39 ++++++++----------- .../OnPropertyListConditionTests.java | 2 +- .../OnWsdlLocationsConditionTests.java | 6 +-- .../WebServicesAutoConfigurationTests.java | 12 +++--- .../appendix-application-properties.adoc | 4 +- .../main/asciidoc/spring-boot-features.adoc | 2 +- ...tionJsonEnvironmentPostProcessorTests.java | 1 - 9 files changed, 32 insertions(+), 42 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java index 6566b819e6..308e5e123a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java @@ -55,7 +55,7 @@ public class BackgroundPreinitializer /** * System property that instructs Spring Boot how to run pre initialization. When the - * property is set to {@code true}, no pre intialization happens and each item is + * property is set to {@code true}, no pre-initialization happens and each item is * initialized in the foreground as it needs to. When the property is {@code false} * (default), pre initialization runs in a separate thread in the background. * @since 2.1.0 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpProperties.java index 0ec8c88137..ef8a265a56 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpProperties.java @@ -43,7 +43,7 @@ public class HttpProperties { /** * HTTP encoding properties. */ - private Encoding encoding = new Encoding(); + private final Encoding encoding = new Encoding(); public boolean isLogRequestDetails() { return this.logRequestDetails; @@ -57,10 +57,6 @@ public class HttpProperties { return this.encoding; } - public void setEncoding(Encoding encoding) { - this.encoding = encoding; - } - /** * Configuration properties for http encoding. */ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/ConcurrentKafkaListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/ConcurrentKafkaListenerContainerFactoryConfigurer.java index 11dcb63293..e1f104b000 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/ConcurrentKafkaListenerContainerFactoryConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/ConcurrentKafkaListenerContainerFactoryConfigurer.java @@ -117,38 +117,33 @@ public class ConcurrentKafkaListenerContainerFactoryConfigurer { private void configureListenerFactory( ConcurrentKafkaListenerContainerFactory factory) { - PropertyMapper map = PropertyMapper.get(); + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); Listener properties = this.properties.getListener(); - map.from(properties::getConcurrency).whenNonNull().to(factory::setConcurrency); - map.from(this.messageConverter).whenNonNull().to(factory::setMessageConverter); - map.from(this.replyTemplate).whenNonNull().to(factory::setReplyTemplate); + map.from(properties::getConcurrency).to(factory::setConcurrency); + map.from(this.messageConverter).to(factory::setMessageConverter); + map.from(this.replyTemplate).to(factory::setReplyTemplate); map.from(properties::getType).whenEqualTo(Listener.Type.BATCH) .toCall(() -> factory.setBatchListener(true)); - map.from(this.errorHandler).whenNonNull().to(factory::setErrorHandler); - map.from(this.afterRollbackProcessor).whenNonNull() - .to(factory::setAfterRollbackProcessor); + map.from(this.errorHandler).to(factory::setErrorHandler); + map.from(this.afterRollbackProcessor).to(factory::setAfterRollbackProcessor); } private void configureContainer(ContainerProperties container) { - PropertyMapper map = PropertyMapper.get(); + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); Listener properties = this.properties.getListener(); - map.from(properties::getAckMode).whenNonNull().to(container::setAckMode); - map.from(properties::getClientId).whenNonNull().to(container::setClientId); - map.from(properties::getAckCount).whenNonNull().to(container::setAckCount); - map.from(properties::getAckTime).whenNonNull().as(Duration::toMillis) - .to(container::setAckTime); - map.from(properties::getPollTimeout).whenNonNull().as(Duration::toMillis) + map.from(properties::getAckMode).to(container::setAckMode); + map.from(properties::getClientId).to(container::setClientId); + map.from(properties::getAckCount).to(container::setAckCount); + map.from(properties::getAckTime).as(Duration::toMillis).to(container::setAckTime); + map.from(properties::getPollTimeout).as(Duration::toMillis) .to(container::setPollTimeout); - map.from(properties::getNoPollThreshold).whenNonNull() - .to(container::setNoPollThreshold); - map.from(properties::getIdleEventInterval).whenNonNull().as(Duration::toMillis) + map.from(properties::getNoPollThreshold).to(container::setNoPollThreshold); + map.from(properties::getIdleEventInterval).as(Duration::toMillis) .to(container::setIdleEventInterval); - map.from(properties::getMonitorInterval).whenNonNull().as(Duration::getSeconds) + map.from(properties::getMonitorInterval).as(Duration::getSeconds) .as(Number::intValue).to(container::setMonitorInterval); - map.from(properties::getLogContainerConfig).whenNonNull() - .to(container::setLogContainerConfig); - map.from(this.transactionManager).whenNonNull() - .to(container::setTransactionManager); + map.from(properties::getLogContainerConfig).to(container::setLogContainerConfig); + map.from(this.transactionManager).to(container::setTransactionManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnPropertyListConditionTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnPropertyListConditionTests.java index 8794881f8d..d3ca046ecc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnPropertyListConditionTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnPropertyListConditionTests.java @@ -54,7 +54,7 @@ public class OnPropertyListConditionTests { @Test public void propertyDefinedAsCommaSeparatedRelaxed() { - this.contextRunner.withPropertyValues("spring.test.my-list=value1") + this.contextRunner.withPropertyValues("spring.test.myList=value1") .run((context) -> assertThat(context).hasBean("foo")); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/OnWsdlLocationsConditionTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/OnWsdlLocationsConditionTests.java index 69605a9e03..4de3a6f673 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/OnWsdlLocationsConditionTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/OnWsdlLocationsConditionTests.java @@ -37,18 +37,18 @@ public class OnWsdlLocationsConditionTests { .withUserConfiguration(TestConfig.class); @Test - public void bootstrapHostsNotDefined() { + public void wsdlLocationsNotDefined() { this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("foo")); } @Test - public void bootstrapHostsDefinedAsCommaSeparated() { + public void wsdlLocationsDefinedAsCommaSeparated() { this.contextRunner.withPropertyValues("spring.webservices.wsdl-locations=value1") .run((context) -> assertThat(context).hasBean("foo")); } @Test - public void bootstrapHostsDefinedAsList() { + public void wsdlLocationsDefinedAsList() { this.contextRunner .withPropertyValues("spring.webservices.wsdl-locations[0]=value1") .run((context) -> assertThat(context).hasBean("foo")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java index 1bfc1c7deb..840d4f34a6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java @@ -99,9 +99,9 @@ public class WebServicesAutoConfigurationTests { .withPropertyValues("spring.webservices.wsdl-locations=classpath:/wsdl") .run((context) -> { assertThat(context.getBeansOfType(SimpleWsdl11Definition.class)) - .hasSize(1).containsKey("service"); - assertThat(context.getBeansOfType(SimpleXsdSchema.class)).hasSize(1) - .containsKey("types"); + .containsOnlyKeys("service"); + assertThat(context.getBeansOfType(SimpleXsdSchema.class)) + .containsOnlyKeys("types"); }); } @@ -112,9 +112,9 @@ public class WebServicesAutoConfigurationTests { "spring.webservices.wsdl-locations[0]=classpath:/wsdl") .run((context) -> { assertThat(context.getBeansOfType(SimpleWsdl11Definition.class)) - .hasSize(1).containsKey("service"); - assertThat(context.getBeansOfType(SimpleXsdSchema.class)).hasSize(1) - .containsKey("types"); + .containsOnlyKeys("service"); + assertThat(context.getBeansOfType(SimpleXsdSchema.class)) + .containsOnlyKeys("types"); }); } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 68a800641e..b37c823665 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -181,7 +181,7 @@ content into your application. Rather, pick only the properties that you need. server.address= # Network address to which the server should bind. server.compression.enabled=false # Whether response compression is enabled. server.compression.excluded-user-agents= # List of user-agents to exclude from compression. - server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript # Comma-separated list of MIME types that should be compressed. + server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml # Comma-separated list of MIME types that should be compressed. server.compression.min-response-size=2048 # Minimum "Content-Length" value that is required for compression to be performed. server.connection-timeout= # Time that connectors wait for another HTTP request before closing the connection. When not set, the connector's container-specific default is used. Use a value of -1 to indicate no (that is, an infinite) timeout. server.error.include-exception=false # Include the "exception" attribute. @@ -328,7 +328,7 @@ content into your application. Rather, pick only the properties that you need. # SPRING HATEOAS ({sc-spring-boot-autoconfigure}/hateoas/HateoasProperties.{sc-ext}[HateoasProperties]) spring.hateoas.use-hal-as-default-json-media-type=true # Whether application/hal+json responses should be sent to requests that accept application/json. - # HTTP ({sc-spring-boot-autoconfigure}/http/HttpEncodingProperties.{sc-ext}[HttpProperties]) + # HTTP ({sc-spring-boot-autoconfigure}/http/HttpProperties.{sc-ext}[HttpProperties]) spring.http.converters.preferred-json-mapper= # Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment. spring.http.encoding.charset=UTF-8 # Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly. spring.http.encoding.enabled=true # Whether to enable http encoding support. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 4dfc15a9dd..17bafd476d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -5734,7 +5734,7 @@ container factory. Similarly, if a `RecordMessageConverter`, `ErrorHandler` or factory. TIP: A custom `ChainedKafkaTransactionManager` must be marked `@Primary` as it usually -reference the auto-configured `KafkaTransactionManager` bean. +references the auto-configured `KafkaTransactionManager` bean. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java index 574ffe8ba1..e19cca9c70 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java @@ -54,7 +54,6 @@ public class SpringApplicationJsonEnvironmentPostProcessorTests { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.application.json=foo:bar"); this.processor.postProcessEnvironment(this.environment, null); - assertThat(this.environment.resolvePlaceholders("${foo:}")).isEmpty(); } @Test