From aa57ca7e189c8b4b67140061b2b67d5b7e15ee22 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 6 Jul 2017 16:52:53 -0700 Subject: [PATCH] Polish --- .../boot/actuate/endpoint/HealthEndpoint.java | 10 ++- .../endpoint/mvc/HealthMvcEndpoint.java | 21 ++--- .../OAuth2RestOperationsConfiguration.java | 4 +- .../autoconfigure/web/ResourceProperties.java | 2 +- .../data/neo4j/Neo4jPropertiesTests.java | 3 +- ...Auth2RestOperationsConfigurationTests.java | 11 ++- .../web/ResourcePropertiesTests.java | 5 +- ...assLoaderFilesResourcePatternResolver.java | 55 ++++++------ .../src/main/asciidoc/deployment.adoc | 79 ++++++++--------- spring-boot-docs/src/main/asciidoc/howto.adoc | 1 + .../asciidoc/production-ready-features.adoc | 10 ++- .../main/asciidoc/spring-boot-features.adoc | 88 +++++++++---------- .../EnvironmentPostProcessorExample.java | 13 ++- .../EnvironmentPostProcessorExampleTests.java | 4 +- .../launchscript/SysVinitLaunchScriptIT.java | 2 +- ...TestWithAutoConfigureJsonTestersTests.java | 12 ++- .../boot/gradle/run/FindMainClassTask.java | 2 +- .../boot/loader/jar/JarURLConnection.java | 6 +- .../boot/maven/RepackageMojo.java | 3 +- .../boot/EnvironmentConverter.java | 1 - .../config/ConfigFileApplicationListener.java | 8 +- ...dertowEmbeddedServletContainerFactory.java | 1 - ...urationPropertiesBindingPostProcessor.java | 4 +- .../logging/LoggingApplicationListener.java | 2 +- ...wEmbeddedServletContainerFactoryTests.java | 7 +- .../LoggingApplicationListenerTests.java | 12 ++- 26 files changed, 192 insertions(+), 174 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java index abe0b7a525..5c6b621e4c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * 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. @@ -69,8 +69,12 @@ public class HealthEndpoint extends AbstractEndpoint { return this.timeToLive; } - public void setTimeToLive(long ttl) { - this.timeToLive = ttl; + /** + * Set the time to live for cached results. + * @param timeToLive the time to live in milliseconds + */ + public void setTimeToLive(long timeToLive) { + this.timeToLive = timeToLive; } /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java index 48b73d2a81..3f55eb55d1 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java @@ -172,20 +172,13 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter= getDelegate().getTimeToLive(); + return cached.getHealth(); } protected boolean exposeHealthDetails(HttpServletRequest request, @@ -241,6 +234,14 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter= timeToLive; + } + + public Health getHealth() { + return this.health; + } + } } 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 78d8afd582..3c5c983d8d 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 @@ -107,8 +107,8 @@ public class OAuth2RestOperationsConfiguration { private final AccessTokenRequest accessTokenRequest; - public ClientContextConfiguration(@Qualifier("accessTokenRequest") - ObjectProvider accessTokenRequest) { + public ClientContextConfiguration( + @Qualifier("accessTokenRequest") ObjectProvider accessTokenRequest) { this.accessTokenRequest = accessTokenRequest.getIfAvailable(); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index 4cd73676a2..2cd70ce584 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -93,7 +93,7 @@ public class ResourceProperties implements ResourceLoaderAware { String[] normalized = new String[staticLocations.length]; for (int i = 0; i < staticLocations.length; i++) { String location = staticLocations[i]; - normalized[i] = location.endsWith("/") ? location : location + "/"; + normalized[i] = (location.endsWith("/") ? location : location + "/"); } return normalized; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java index 7f99ad89fd..e9c3f76619 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java @@ -76,7 +76,8 @@ public class Neo4jPropertiesTests { Neo4jProperties properties = load(true, "spring.data.neo4j.uri=https://localhost:7474"); Configuration configuration = properties.createConfiguration(); - assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "https://localhost:7474"); + assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, + "https://localhost:7474"); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java index 0e3c987b46..9d5e2fed55 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java @@ -47,13 +47,18 @@ public class OAuth2RestOperationsConfigurationTests { public void clientIdConditionMatches() throws Exception { EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.client.client-id=acme"); - this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run(); - assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class)).isNotNull(); + this.context = new SpringApplicationBuilder( + OAuth2RestOperationsConfiguration.class).environment(this.environment) + .web(false).run(); + assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class)) + .isNotNull(); } @Test public void clientIdConditionDoesNotMatch() throws Exception { - this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run(); + this.context = new SpringApplicationBuilder( + OAuth2RestOperationsConfiguration.class).environment(this.environment) + .web(false).run(); this.thrown.expect(NoSuchBeanDefinitionException.class); this.context.getBean(OAuth2RestOperationsConfiguration.class); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java index 48393aec54..064bf4b58a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java @@ -63,9 +63,8 @@ public class ResourcePropertiesTests { @Test public void customStaticLocationsAreNormalizedToEndWithTrailingSlash() { this.properties.setStaticLocations(new String[] { "/foo", "/bar", "/baz/" }); - assertThat(this.properties.getStaticLocations()).containsExactly("/foo/", "/bar/", - "/baz/"); - + String[] actual = this.properties.getStaticLocations(); + assertThat(actual).containsExactly("/foo/", "/bar/", "/baz/"); } } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java index 119a4159fd..a7935dd5b3 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java @@ -22,7 +22,6 @@ import java.lang.reflect.Field; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map.Entry; @@ -208,21 +207,27 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe public ResourcePatternResolver getResourcePatternResolver( ApplicationContext applicationContext, ResourceLoader resourceLoader) { - return new PathMatchingResourcePatternResolver(resourceLoader == null - ? createResourceLoader(applicationContext) : resourceLoader); + if (resourceLoader == null) { + resourceLoader = new DefaultResourceLoader(); + copyProtocolResolvers(applicationContext, resourceLoader); + } + return new PathMatchingResourcePatternResolver(resourceLoader); } - private ResourceLoader createResourceLoader( - ApplicationContext applicationContext) { - DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); - if (applicationContext instanceof DefaultResourceLoader) { - Collection protocolResolvers = ((DefaultResourceLoader) applicationContext) - .getProtocolResolvers(); - for (ProtocolResolver protocolResolver : protocolResolvers) { - resourceLoader.addProtocolResolver(protocolResolver); - } + protected final void copyProtocolResolvers(ApplicationContext applicationContext, + ResourceLoader resourceLoader) { + if (applicationContext instanceof DefaultResourceLoader + && resourceLoader instanceof DefaultResourceLoader) { + copyProtocolResolvers((DefaultResourceLoader) applicationContext, + (DefaultResourceLoader) resourceLoader); + } + } + + protected final void copyProtocolResolvers(DefaultResourceLoader source, + DefaultResourceLoader destination) { + for (ProtocolResolver resolver : source.getProtocolResolvers()) { + destination.addProtocolResolver(resolver); } - return resourceLoader; } } @@ -238,25 +243,21 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe public ResourcePatternResolver getResourcePatternResolver( ApplicationContext applicationContext, ResourceLoader resourceLoader) { if (applicationContext instanceof WebApplicationContext) { - return new ServletContextResourcePatternResolver(resourceLoader == null - ? createResourceLoader((WebApplicationContext) applicationContext) - : resourceLoader); + return getResourcePatternResolver( + (WebApplicationContext) applicationContext, resourceLoader); } return super.getResourcePatternResolver(applicationContext, resourceLoader); } - private ResourceLoader createResourceLoader( - WebApplicationContext applicationContext) { - WebApplicationContextResourceLoader resourceLoader = new WebApplicationContextResourceLoader( - applicationContext); - if (applicationContext instanceof DefaultResourceLoader) { - Collection protocolResolvers = ((DefaultResourceLoader) applicationContext) - .getProtocolResolvers(); - for (ProtocolResolver protocolResolver : protocolResolvers) { - resourceLoader.addProtocolResolver(protocolResolver); - } + private ResourcePatternResolver getResourcePatternResolver( + WebApplicationContext applicationContext, ResourceLoader resourceLoader) { + if (resourceLoader == null) { + resourceLoader = new WebApplicationContextResourceLoader( + applicationContext); + copyProtocolResolvers(applicationContext, resourceLoader); } - return resourceLoader; + return new ServletContextResourcePatternResolver(resourceLoader); + } } diff --git a/spring-boot-docs/src/main/asciidoc/deployment.adoc b/spring-boot-docs/src/main/asciidoc/deployment.adoc index 5136bb00dc..c6b29827e8 100644 --- a/spring-boot-docs/src/main/asciidoc/deployment.adoc +++ b/spring-boot-docs/src/main/asciidoc/deployment.adoc @@ -440,65 +440,64 @@ Maven build to run the app. [[cloud-deployment-gae]] === Google Cloud - -Google Cloud has several options that could be used to launch Spring Boot applications. The -easiest to get started with is probably App Engine, but you could also find ways to run -Spring Boot in a container with Container Engine, or on a virtual machine using Compute Engine. - -To run in App Engine you can create a project in the UI first, which -sets up a unique identifier for you and also HTTP routes. Add a Java -app to the project and leave it empty, then use the -https://cloud.google.com/sdk/downloads[Google Cloud SDK] to push your +Google Cloud has several options that could be used to launch Spring Boot applications. +The easiest to get started with is probably App Engine, but you could also find ways to +run Spring Boot in a container with Container Engine, or on a virtual machine using +Compute Engine. + +To run in App Engine you can create a project in the UI first, which sets up a unique +identifier for you and also HTTP routes. Add a Java app to the project and leave it empty, +then use the https://cloud.google.com/sdk/downloads[Google Cloud SDK] to push your Spring Boot app into that slot from the command line or CI build. -App Engine needs you to create an `app.yaml` file to describe the -resources your app requires. Normally you put this in -`src/min/appengine`, and it looks something like this: +App Engine needs you to create an `app.yaml` file to describe the resources your app +requires. Normally you put this in `src/min/appengine`, and it looks something like this: [source,yaml,indent=0] ---- -service: default + service: default -runtime: java -env: flex + runtime: java + env: flex -runtime_config: - jdk: openjdk8 + runtime_config: + jdk: openjdk8 -handlers: -- url: /.* - script: this field is required, but ignored + handlers: + - url: /.* + script: this field is required, but ignored -manual_scaling: - instances: 1 + manual_scaling: + instances: 1 -health_check: - enable_health_check: False + health_check: + enable_health_check: False -env_variables: - ENCRYPT_KEY: your_encryption_key_here + env_variables: + ENCRYPT_KEY: your_encryption_key_here ---- -You can deploy the app, for example, with a Maven plugin by simply -adding the project ID to the build configuration: +You can deploy the app, for example, with a Maven plugin by simply adding the project ID +to the build configuration: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- - - com.google.cloud.tools - appengine-maven-plugin - 1.3.0 - - myproject - - + + com.google.cloud.tools + appengine-maven-plugin + 1.3.0 + + myproject + + ---- -Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will fail). +Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will +fail). -NOTE: Google App Engine Classic is tied to the Servlet 2.5 API, so you can't deploy a Spring Application -there without some modifications. See the <> -of this guide. +NOTE: Google App Engine Classic is tied to the Servlet 2.5 API, so you can't deploy a +Spring Application there without some modifications. See the +<> of this guide. diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index bf7dd7a7a1..08b4246cd1 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -137,6 +137,7 @@ key defined via `@PropertySource` will be loaded too late to have any effect on auto-configuration. + [[howto-build-an-application-context-hierarchy]] === Build an ApplicationContext hierarchy (adding a parent or root context) You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext` diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index cdb0412334..166ef737f1 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -283,10 +283,12 @@ returned, and for an authenticated connection additional details are also displa Health information is collected from all {sc-spring-boot-actuator}/health/HealthIndicator.{sc-ext}[`HealthIndicator`] beans defined in your `ApplicationContext`. Spring Boot includes a number of auto-configured -`HealthIndicators` and you can also write your own. By default, the final system state is derived -by the `HealthAggregator` which sorts the statuses from each `HealthIndicator` based on an ordered list of statuses. -The first status in the sorted list is used as the overall health status. -If no `HealthIndicator` returns a status that is known to the `HealthAggregator`, an `UNKNOWN` status is used. +`HealthIndicators` and you can also write your own. By default, the final system state is +derived by the `HealthAggregator` which sorts the statuses from each `HealthIndicator` +based on an ordered list of statuses. The first status in the sorted list is used as the +overall health status. If no `HealthIndicator` returns a status that is known to the +`HealthAggregator`, an `UNKNOWN` status is used. + === Security with HealthIndicators 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 e3c5308504..3ecca74b92 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2474,8 +2474,8 @@ and `AuthenticationManagerConfiguration` for authentication configuration which relevant in non-web applications). To switch off the default web application security configuration completely you can add a bean with `@EnableWebSecurity` (this does not disable the authentication manager configuration or Actuator's security). -To customize it you normally use external properties and beans of type `WebSecurityConfigurerAdapter` -(e.g. to add form-based login). +To customize it you normally use external properties and beans of type +`WebSecurityConfigurerAdapter` (e.g. to add form-based login). NOTE: If you add `@EnableWebSecurity` and also disable Actuator security, you will get the default form-based login for the entire application unless you add a custom @@ -6027,7 +6027,7 @@ where one will be auto-configured for you. [source,java,indent=0] ---- -EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot"); + EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot"); ---- @@ -6040,25 +6040,25 @@ for assertions: [source,java,indent=0] ---- -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; + import org.junit.Rule; + import org.junit.Test; + import org.springframework.boot.test.rule.OutputCapture; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; + import static org.hamcrest.Matchers.*; + import static org.junit.Assert.*; -public class MyTest { + public class MyTest { - @Rule - public OutputCapture capture = new OutputCapture(); + @Rule + public OutputCapture capture = new OutputCapture(); - @Test - public void testName() throws Exception { - System.out.println("Hello World!"); - assertThat(capture.toString(), containsString("World")); - } + @Test + public void testName() throws Exception { + System.out.println("Hello World!"); + assertThat(capture.toString(), containsString("World")); + } -} + } ---- [[boot-features-rest-templates-test-utility]] @@ -6079,17 +6079,17 @@ features will be enabled: [source,java,indent=0] ---- -public class MyTest { + public class MyTest { - private TestRestTemplate template = new TestRestTemplate(); + private TestRestTemplate template = new TestRestTemplate(); - @Test - public void testRequest() throws Exception { - HttpHeaders headers = template.getForEntity("http://myhost.com/example", String.class).getHeaders(); - assertThat(headers.getLocation().toString(), containsString("myotherhost")); - } + @Test + public void testRequest() throws Exception { + HttpHeaders headers = template.getForEntity("http://myhost.com/example", String.class).getHeaders(); + assertThat(headers.getLocation().toString(), containsString("myotherhost")); + } -} + } ---- Alternatively, if you are using the `@SpringBootTest` annotation with @@ -6100,32 +6100,32 @@ specify a host and port will automatically connect to the embedded server: [source,java,indent=0] ---- -@RunWith(SpringRunner.class) -@SpringBootTest -public class MyTest { + @RunWith(SpringRunner.class) + @SpringBootTest + public class MyTest { - @Autowired - private TestRestTemplate template; + @Autowired + private TestRestTemplate template; - @Test - public void testRequest() throws Exception { - HttpHeaders headers = template.getForEntity("/example", String.class).getHeaders(); - assertThat(headers.getLocation().toString(), containsString("myotherhost")); - } + @Test + public void testRequest() throws Exception { + HttpHeaders headers = template.getForEntity("/example", String.class).getHeaders(); + assertThat(headers.getLocation().toString(), containsString("myotherhost")); + } - @TestConfiguration - static class Config { + @TestConfiguration + static class Config { + + @Bean + public RestTemplateBuilder restTemplateBuilder() { + return new RestTemplateBuilder() + .additionalMessageConverters(...) + .customizers(...); + } - @Bean - public RestTemplateBuilder restTemplateBuilder() { - return new RestTemplateBuilder() - .additionalMessageConverters(...) - .customizers(...); } } - -} ---- diff --git a/spring-boot-docs/src/main/java/org/springframework/boot/context/EnvironmentPostProcessorExample.java b/spring-boot-docs/src/main/java/org/springframework/boot/context/EnvironmentPostProcessorExample.java index cb94961c5e..b4bb149181 100644 --- a/spring-boot-docs/src/main/java/org/springframework/boot/context/EnvironmentPostProcessorExample.java +++ b/spring-boot-docs/src/main/java/org/springframework/boot/context/EnvironmentPostProcessorExample.java @@ -32,11 +32,9 @@ import org.springframework.core.io.Resource; * @author Stephane Nicoll */ // tag::example[] -public class EnvironmentPostProcessorExample - implements EnvironmentPostProcessor { +public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor { - private final YamlPropertySourceLoader loader - = new YamlPropertySourceLoader(); + private final YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); @Override public void postProcessEnvironment(ConfigurableEnvironment environment, @@ -48,15 +46,14 @@ public class EnvironmentPostProcessorExample private PropertySource loadYaml(Resource path) { if (!path.exists()) { - throw new IllegalArgumentException("Resource " + path - + " does not exist"); + throw new IllegalArgumentException("Resource " + path + " does not exist"); } try { return this.loader.load("custom-resource", path, null); } catch (IOException ex) { - throw new IllegalStateException("Failed to load yaml configuration " - + "from " + path, ex); + throw new IllegalStateException( + "Failed to load yaml configuration from " + path, ex); } } diff --git a/spring-boot-docs/src/test/java/org/springframework/boot/context/EnvironmentPostProcessorExampleTests.java b/spring-boot-docs/src/test/java/org/springframework/boot/context/EnvironmentPostProcessorExampleTests.java index 6030a4ad7d..855e4cd325 100644 --- a/spring-boot-docs/src/test/java/org/springframework/boot/context/EnvironmentPostProcessorExampleTests.java +++ b/spring-boot-docs/src/test/java/org/springframework/boot/context/EnvironmentPostProcessorExampleTests.java @@ -35,8 +35,8 @@ public class EnvironmentPostProcessorExampleTests { @Test public void applyEnvironmentPostProcessor() { assertThat(this.environment.containsProperty("test.foo.bar")).isFalse(); - new EnvironmentPostProcessorExample().postProcessEnvironment( - this.environment, new SpringApplication()); + new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment, + new SpringApplication()); assertThat(this.environment.containsProperty("test.foo.bar")).isTrue(); assertThat(this.environment.getProperty("test.foo.bar")).isEqualTo("value"); } diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index 07a5725b0b..cc94762b74 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * 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. diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java index 5137c66c3e..8c997427ba 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java @@ -29,6 +29,8 @@ import org.springframework.boot.test.json.JacksonTester; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration tests for {@link SpringBootTest} with {@link AutoConfigureJsonTesters}. * @@ -41,17 +43,19 @@ import org.springframework.test.context.junit4.SpringRunner; public class SpringBootTestWithAutoConfigureJsonTestersTests { @Autowired - BasicJsonTester basicJson; + private BasicJsonTester basicJson; @Autowired - JacksonTester jacksonTester; + private JacksonTester jacksonTester; @Autowired - GsonTester gsonTester; + private GsonTester gsonTester; @Test public void contextLoads() { - + assertThat(this.basicJson).isNotNull(); + assertThat(this.jacksonTester).isNotNull(); + assertThat(this.gsonTester).isNotNull(); } } diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/FindMainClassTask.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/FindMainClassTask.java index ce35c01c41..fbb01c8777 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/FindMainClassTask.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/FindMainClassTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * 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. diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 3a6d6fd231..584bce227c 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -187,11 +187,11 @@ final class JarURLConnection extends java.net.JarURLConnection { @Override public int getContentLength() { - long longContentLength = getContentLengthLong(); - if (longContentLength > Integer.MAX_VALUE) { + long length = getContentLengthLong(); + if (length > Integer.MAX_VALUE) { return -1; } - return (int) longContentLength; + return (int) length; } @Override diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index 9302eadc15..ced1f32b16 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -151,8 +151,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { /** * Make a fully executable jar for *nix machines by prepending a launch script to the - * jar. - *
+ * jar.
* Currently, some tools do not accept this format so you may not always be able to * use this technique. For example, jar -xf may silently fail to extract * a jar or war that has been made fully-executable. It is recommended that you only diff --git a/spring-boot/src/main/java/org/springframework/boot/EnvironmentConverter.java b/spring-boot/src/main/java/org/springframework/boot/EnvironmentConverter.java index 8501759b41..d99ca1cf1d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/EnvironmentConverter.java +++ b/spring-boot/src/main/java/org/springframework/boot/EnvironmentConverter.java @@ -65,7 +65,6 @@ final class EnvironmentConverter { * environment is already a {@code StandardEnvironment} and is not a * {@link ConfigurableWebEnvironment} no conversion is performed and it is returned * unchanged. - * * @param environment The Environment to convert * @return The converted Environment */ diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 1776bac9dc..ee50c48d6b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -101,8 +101,8 @@ import org.springframework.validation.BindException; * @author Andy Wilkinson * @author EddĂș MelĂ©ndez */ -public class ConfigFileApplicationListener implements EnvironmentPostProcessor, - SmartApplicationListener, Ordered { +public class ConfigFileApplicationListener + implements EnvironmentPostProcessor, SmartApplicationListener, Ordered { private static final String DEFAULT_PROPERTIES = "defaultProperties"; @@ -153,8 +153,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, @Override public boolean supportsEventType(Class eventType) { - return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) || - ApplicationPreparedEvent.class.isAssignableFrom(eventType); + return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) + || ApplicationPreparedEvent.class.isAssignableFrom(eventType); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index 475e3d6c7c..942bc01727 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -321,7 +321,6 @@ public class UndertowEmbeddedServletContainerFactory keyManagerFactory.getKeyManagers()); } return keyManagerFactory.getKeyManagers(); - } catch (Exception ex) { throw new IllegalStateException(ex); 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 17ccdf9e8a..e08a7476e9 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 @@ -420,8 +420,8 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc if (AnnotatedElementUtils.hasAnnotation(type, Validated.class)) { return true; } - if (type.getPackage() != null && - type.getPackage().getName().startsWith("org.springframework.boot")) { + if (type.getPackage() != null && type.getPackage().getName() + .startsWith("org.springframework.boot")) { return false; } if (getConstraintsForClass(type).isBeanConstrained()) { diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index 215ce64df2..209f7fcaf8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -346,7 +346,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { String name = entry.getKey(); if (name.equalsIgnoreCase(LoggingSystem.ROOT_LOGGER_NAME)) { if (rootProcessed) { - return; + continue; } name = null; rootProcessed = true; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java index f8a30c1bca..752fd71f8b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java @@ -257,8 +257,11 @@ public class UndertowEmbeddedServletContainerFactoryTests UndertowEmbeddedServletContainerFactory factory = getFactory(); Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks"); factory.setSsl(ssl); - KeyManager[] keyManagers = ReflectionTestUtils.invokeMethod(factory, "getKeyManagers"); - Class name = Class.forName("org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory$ConfigurableAliasKeyManager"); + KeyManager[] keyManagers = ReflectionTestUtils.invokeMethod(factory, + "getKeyManagers"); + Class name = Class + .forName("org.springframework.boot.context.embedded.undertow." + + "UndertowEmbeddedServletContainerFactory$ConfigurableAliasKeyManager"); assertThat(keyManagers[0]).isNotInstanceOf(name); } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index 016b52eba1..80e2ccfa61 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -485,10 +485,14 @@ public class LoggingApplicationListenerTests { } @Test - public void lowPriorityPropertySourceShouldNotOverrideRootLoggerConfig() throws Exception { - MutablePropertySources propertySources = this.context.getEnvironment().getPropertySources(); - propertySources.addFirst(new MapPropertySource("test1", Collections.singletonMap("logging.level.ROOT", "DEBUG"))); - propertySources.addLast(new MapPropertySource("test2", Collections.singletonMap("logging.level.root", "WARN"))); + public void lowPriorityPropertySourceShouldNotOverrideRootLoggerConfig() + throws Exception { + MutablePropertySources propertySources = this.context.getEnvironment() + .getPropertySources(); + propertySources.addFirst(new MapPropertySource("test1", + Collections.singletonMap("logging.level.ROOT", "DEBUG"))); + propertySources.addLast(new MapPropertySource("test2", + Collections.singletonMap("logging.level.root", "WARN"))); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); this.logger.debug("testatdebug");