From 521f746151f549cd235d6398631ea0d538ff3b73 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 20 Sep 2018 02:47:56 +0900 Subject: [PATCH] Polish Closes gh-14517 --- .../quartz/QuartzAutoConfigurationTests.java | 1 - .../asciidoc/appendix-application-properties.adoc | 3 ++- .../src/main/asciidoc/spring-boot-features.adoc | 6 +++--- .../WebTestClientAutoConfigurationTests.java | 2 +- ...ngBootTestRandomPortEnvironmentPostProcessor.java | 7 ++++--- .../test/mock/mockito/MockitoPostProcessorTests.java | 10 +++++----- ...tTestRandomPortEnvironmentPostProcessorTests.java | 7 +++---- .../context/logging/LoggingApplicationListener.java | 12 ++++++------ .../boot/convert/ApplicationConversionService.java | 3 ++- .../additional-spring-configuration-metadata.json | 8 ++++---- .../sample/simple/service/HelloWorldService.java | 4 ---- 11 files changed, 30 insertions(+), 33 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java index 0dcf5be66d..c1cd6f74e2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java @@ -254,7 +254,6 @@ public class QuartzAutoConfigurationTests { "spring.quartz.scheduler-name=testScheduler", "spring.quartz.auto-startup=false", "spring.quartz.startup-delay=1m", "spring.quartz.wait-for-jobs-to-complete-on-shutdown=true", - "spring.quartz.wait-for-jobs-to-complete-on-shutdown=true", "spring.quartz.overwrite-existing-jobs=true").run((context) -> { assertThat(context).hasSingleBean(SchedulerFactoryBean.class); SchedulerFactoryBean schedulerFactory = context 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 ebf56b7288..1fc1d2feb0 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 @@ -36,6 +36,7 @@ content into your application. Rather, pick only the properties that you need. logging.file= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory. logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup. logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup. + logging.group.*= # Log groups to quickly change multiple loggers at the same time. For instance, `logging.level.db=org.hibernate,org.springframework.jdbc`. logging.level.*= # Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`. logging.path= # Location of the log file. For instance, `/var/log`. logging.pattern.console= # Appender pattern for output to the console. Supported only with the default Logback setup. @@ -147,10 +148,10 @@ content into your application. Rather, pick only the properties that you need. spring.quartz.jdbc.initialize-schema=embedded # Database schema initialization mode. spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.quartz.job-store-type=memory # Quartz job store type. + spring.quartz.overwrite-existing-jobs=false # Whether configured jobs should overwrite existing job definitions. spring.quartz.properties.*= # Additional Quartz Scheduler properties. spring.quartz.scheduler-name=quartzScheduler # Name of the scheduler. spring.quartz.startup-delay=0s # Delay after which the scheduler is started once initialization completes. - spring.quartz.overwrite-existing-jobs=false # Whether configured jobs should overwrite existing job definitions. spring.quartz.wait-for-jobs-to-complete-on-shutdown=false # Whether to wait for running jobs to complete on shutdown. # REACTOR ({sc-spring-boot-autoconfigure}/reactor/core/ReactorCoreProperties.{sc-ext}[ReactorCoreProperties]) 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 855c9bdb7d..1461b7999e 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 @@ -1735,11 +1735,11 @@ The following example shows potential logging settings in `application.propertie === Log Groups It's often useful to be able to group related loggers together so that they can all be configured at the same time. For example, you might commonly change the logging levels for -_all_ Tomcat related loggers, but you can't easily remember to top level packages. +_all_ Tomcat related loggers, but you can't easily remember top level packages. -To help with this, Spring Boot allows you do define logging groups in your Spring +To help with this, Spring Boot allows you to define logging groups in your Spring `Environment`. For example, here's how you could define a "`tomcat`" group by adding -it to your `appplication.properties`: +it to your `application.properties`: [source,properties,indent=0,subs="verbatim,quotes,attributes"] ---- diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java index 3801dbb973..174213bcc0 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java @@ -116,7 +116,7 @@ public class WebTestClientAutoConfigurationTests { .getField(builder, "httpHandlerBuilder"); List filters = (List) ReflectionTestUtils .getField(httpHandlerBuilder, "filters"); - assertThat(filters.size()).isEqualTo(0); + assertThat(filters).isEmpty(); }); } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java index ce9f6ab91a..282d9ffa34 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java @@ -45,10 +45,11 @@ public class SpringBootTestRandomPortEnvironmentPostProcessor .get(TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); if (isTestServerPortRandom(source)) { if (source.getProperty(MANAGEMENT_PORT_PROPERTY) == null) { - String managementPort = getPort(environment, MANAGEMENT_PORT_PROPERTY, + String managementPort = getProperty(environment, MANAGEMENT_PORT_PROPERTY, null); - String serverPort = getPort(environment, SERVER_PORT_PROPERTY, "8080"); if (managementPort != null && !managementPort.equals("-1")) { + String serverPort = getProperty(environment, SERVER_PORT_PROPERTY, + "8080"); if (!managementPort.equals(serverPort)) { source.getSource().put(MANAGEMENT_PORT_PROPERTY, "0"); } @@ -65,7 +66,7 @@ public class SpringBootTestRandomPortEnvironmentPostProcessor return (source != null && "0".equals(source.getProperty(SERVER_PORT_PROPERTY))); } - private String getPort(ConfigurableEnvironment environment, String property, + private String getProperty(ConfigurableEnvironment environment, String property, String defaultValue) { return environment.getPropertySources().stream() .filter((source) -> !source.getName().equals( diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessorTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessorTests.java index 88d4ccbf3d..da7a76a1e3 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessorTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessorTests.java @@ -190,7 +190,7 @@ public class MockitoPostProcessorTests { @Configuration static class MultipleQualifiedBeans { - @MockBean(ExampleService.class) + @MockBean @Qualifier("test") private ExampleService mock; @@ -216,7 +216,7 @@ public class MockitoPostProcessorTests { @Configuration static class MockPrimaryBean { - @MockBean(ExampleService.class) + @MockBean private ExampleService mock; @Bean @@ -236,7 +236,7 @@ public class MockitoPostProcessorTests { @Configuration static class MockQualifiedBean { - @MockBean(ExampleService.class) + @MockBean @Qualifier("test") private ExampleService mock; @@ -257,7 +257,7 @@ public class MockitoPostProcessorTests { @Configuration static class SpyPrimaryBean { - @SpyBean(ExampleService.class) + @SpyBean private ExampleService spy; @Bean @@ -277,7 +277,7 @@ public class MockitoPostProcessorTests { @Configuration static class SpyQualifiedBean { - @SpyBean(ExampleService.class) + @SpyBean @Qualifier("test") private ExampleService spy; diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java index f439f53993..f81c399fee 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java @@ -50,7 +50,6 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests { @Test public void postProcessWhenServerAndManagementPortIsZeroInTestPropertySource() { addTestPropertySource("0", "0"); - this.environment.setProperty("management.server.port", "0"); this.postProcessor.postProcessEnvironment(this.environment, null); assertThat(this.environment.getProperty("server.port")).isEqualTo("0"); assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0"); @@ -81,8 +80,7 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests { addTestPropertySource("0", null); this.postProcessor.postProcessEnvironment(this.environment, null); assertThat(this.environment.getProperty("server.port")).isEqualTo("0"); - assertThat(this.environment.getProperty("management.server.port")) - .isEqualTo(null); + assertThat(this.environment.getProperty("management.server.port")).isNull(); } @Test @@ -100,7 +98,8 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests { @Test public void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDefaultSameInProduction() { - // mgmt port is 8080 which means its on the same port as main server since that is + // mgmt port is 8080 which means it's on the same port as main server since that + // is // null in app properties addTestPropertySource("0", null); Map other = new HashMap<>(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index 4fb6e429cd..2f30d2a23c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -59,7 +59,7 @@ import org.springframework.util.StringUtils; * environment contains a {@code logging.config} property it will be used to bootstrap the * logging system, otherwise a default configuration is used. Regardless, logging levels * will be customized if the environment contains {@code logging.level.*} entries and - * logging groups can be defined with {@code logging.group} . + * logging groups can be defined with {@code logging.group}. *

* Debug and trace logging for Spring, Tomcat, Jetty and Hibernate will be enabled when * the environment contains {@code debug} or {@code trace} properties that aren't set to @@ -150,7 +150,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { private static final Class[] SOURCE_TYPES = { SpringApplication.class, ApplicationContext.class }; - private static AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false); + private static final AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false); private final Log logger = LogFactory.getLog(getClass()); @@ -323,7 +323,8 @@ public class LoggingApplicationListener implements GenericApplicationListener { return; } Binder binder = Binder.get(environment); - Map groups = getGroups(binder); + Map groups = getGroups(); + binder.bind("logging.group", STRING_STRINGS_MAP.withExistingValue(groups)); Map levels = binder.bind("logging.level", STRING_STRING_MAP) .orElseGet(Collections::emptyMap); levels.forEach((name, level) -> { @@ -337,11 +338,10 @@ public class LoggingApplicationListener implements GenericApplicationListener { }); } - private Map getGroups(Binder binder) { + private Map getGroups() { Map groups = new LinkedHashMap<>(); DEFAULT_GROUP_LOGGERS.forEach( (name, loggers) -> groups.put(name, StringUtils.toStringArray(loggers))); - binder.bind("logging.group", STRING_STRINGS_MAP.withExistingValue(groups)); return groups; } @@ -405,7 +405,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { /** * Sets if initialization arguments should be parsed for {@literal debug} and * {@literal trace} properties (usually defined from {@literal --debug} or - * {@literal --trace} command line args. Defaults to {@code true}. + * {@literal --trace} command line args). Defaults to {@code true}. * @param parseArgs if arguments should be parsed */ public void setParseArgs(boolean parseArgs) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/ApplicationConversionService.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/ApplicationConversionService.java index 33aaab3a24..e1d9ec482c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/ApplicationConversionService.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/ApplicationConversionService.java @@ -55,7 +55,8 @@ public class ApplicationConversionService extends FormattingConversionService { /** * Return a shared default {@code ApplicationConversionService} instance, lazily * building it once needed. - * @return the shared {@code ConversionService} instance (never {@code null}) + * @return the shared {@code ApplicationConversionService} instance (never + * {@code null}) */ public static ApplicationConversionService getSharedInstance() { ApplicationConversionService sharedInstance = ApplicationConversionService.sharedInstance; diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index ed3127ef84..d7c990b50f 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -88,15 +88,15 @@ "defaultValue": 0 }, { - "name": "logging.level", + "name": "logging.group", "type": "java.util.Map", - "description": "Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.", + "description": "Log groups to quickly change multiple loggers at the same time. For instance, `logging.level.db=org.hibernate,org.springframework.jdbc`.", "sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener" }, { - "name": "logging.group", + "name": "logging.level", "type": "java.util.Map", - "description": "Log groups to quickly change multipe loggers at the same time. For instance, `logging.level.db=org.hibernate,org.springframework.jdbc`.", + "description": "Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.", "sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener" }, { diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java index 69ea7065dd..56d79f81d9 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java @@ -34,8 +34,4 @@ public class HelloWorldService { return "Hello " + this.name + " for " + this.duration.getSeconds() + " seconds"; } - public Duration getDuration() { - return this.duration; - } - }