Skip to content

Commit aa57ca7

Browse files
committed
Polish
1 parent 222a09c commit aa57ca7

File tree

26 files changed

+192
-174
lines changed

26 files changed

+192
-174
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,8 +69,12 @@ public long getTimeToLive() {
6969
return this.timeToLive;
7070
}
7171

72-
public void setTimeToLive(long ttl) {
73-
this.timeToLive = ttl;
72+
/**
73+
* Set the time to live for cached results.
74+
* @param timeToLive the time to live in milliseconds
75+
*/
76+
public void setTimeToLive(long timeToLive) {
77+
this.timeToLive = timeToLive;
7478
}
7579

7680
/**

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,13 @@ private Health getHealth(HttpServletRequest request, Principal principal) {
172172

173173
private Health getCurrentHealth() {
174174
long accessTime = System.currentTimeMillis();
175-
CachedHealth cachedHealth = this.cachedHealth;
176-
if (isStale(cachedHealth, accessTime)) {
175+
CachedHealth cached = this.cachedHealth;
176+
if (cached == null || cached.isStale(accessTime, getDelegate().getTimeToLive())) {
177177
Health health = getDelegate().invoke();
178178
this.cachedHealth = new CachedHealth(health, accessTime);
179179
return health;
180180
}
181-
return cachedHealth.health;
182-
}
183-
184-
private boolean isStale(CachedHealth cachedHealth, long accessTime) {
185-
if (cachedHealth == null) {
186-
return true;
187-
}
188-
return (accessTime - cachedHealth.creationTime) >= getDelegate().getTimeToLive();
181+
return cached.getHealth();
189182
}
190183

191184
protected boolean exposeHealthDetails(HttpServletRequest request,
@@ -241,6 +234,14 @@ static class CachedHealth {
241234
this.creationTime = creationTime;
242235
}
243236

237+
public boolean isStale(long accessTime, long timeToLive) {
238+
return (accessTime - this.creationTime) >= timeToLive;
239+
}
240+
241+
public Health getHealth() {
242+
return this.health;
243+
}
244+
244245
}
245246

246247
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ protected static class ClientContextConfiguration {
107107

108108
private final AccessTokenRequest accessTokenRequest;
109109

110-
public ClientContextConfiguration(@Qualifier("accessTokenRequest")
111-
ObjectProvider<AccessTokenRequest> accessTokenRequest) {
110+
public ClientContextConfiguration(
111+
@Qualifier("accessTokenRequest") ObjectProvider<AccessTokenRequest> accessTokenRequest) {
112112
this.accessTokenRequest = accessTokenRequest.getIfAvailable();
113113
}
114114

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private String[] appendSlashIfNecessary(String[] staticLocations) {
9393
String[] normalized = new String[staticLocations.length];
9494
for (int i = 0; i < staticLocations.length; i++) {
9595
String location = staticLocations[i];
96-
normalized[i] = location.endsWith("/") ? location : location + "/";
96+
normalized[i] = (location.endsWith("/") ? location : location + "/");
9797
}
9898
return normalized;
9999
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void httpsUriUseHttpDriver() {
7676
Neo4jProperties properties = load(true,
7777
"spring.data.neo4j.uri=https://localhost:7474");
7878
Configuration configuration = properties.createConfiguration();
79-
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "https://localhost:7474");
79+
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
80+
"https://localhost:7474");
8081
}
8182

8283
@Test

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ public class OAuth2RestOperationsConfigurationTests {
4747
public void clientIdConditionMatches() throws Exception {
4848
EnvironmentTestUtils.addEnvironment(this.environment,
4949
"security.oauth2.client.client-id=acme");
50-
this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run();
51-
assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class)).isNotNull();
50+
this.context = new SpringApplicationBuilder(
51+
OAuth2RestOperationsConfiguration.class).environment(this.environment)
52+
.web(false).run();
53+
assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class))
54+
.isNotNull();
5255
}
5356

5457
@Test
5558
public void clientIdConditionDoesNotMatch() throws Exception {
56-
this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run();
59+
this.context = new SpringApplicationBuilder(
60+
OAuth2RestOperationsConfiguration.class).environment(this.environment)
61+
.web(false).run();
5762
this.thrown.expect(NoSuchBeanDefinitionException.class);
5863
this.context.getBean(OAuth2RestOperationsConfiguration.class);
5964
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public void defaultStaticLocationsAllEndWithTrailingSlash() {
6363
@Test
6464
public void customStaticLocationsAreNormalizedToEndWithTrailingSlash() {
6565
this.properties.setStaticLocations(new String[] { "/foo", "/bar", "/baz/" });
66-
assertThat(this.properties.getStaticLocations()).containsExactly("/foo/", "/bar/",
67-
"/baz/");
68-
66+
String[] actual = this.properties.getStaticLocations();
67+
assertThat(actual).containsExactly("/foo/", "/bar/", "/baz/");
6968
}
7069

7170
}

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.MalformedURLException;
2323
import java.net.URL;
2424
import java.util.ArrayList;
25-
import java.util.Collection;
2625
import java.util.List;
2726
import java.util.Map.Entry;
2827

@@ -208,21 +207,27 @@ private static class ResourcePatternResolverFactory {
208207

209208
public ResourcePatternResolver getResourcePatternResolver(
210209
ApplicationContext applicationContext, ResourceLoader resourceLoader) {
211-
return new PathMatchingResourcePatternResolver(resourceLoader == null
212-
? createResourceLoader(applicationContext) : resourceLoader);
210+
if (resourceLoader == null) {
211+
resourceLoader = new DefaultResourceLoader();
212+
copyProtocolResolvers(applicationContext, resourceLoader);
213+
}
214+
return new PathMatchingResourcePatternResolver(resourceLoader);
213215
}
214216

215-
private ResourceLoader createResourceLoader(
216-
ApplicationContext applicationContext) {
217-
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
218-
if (applicationContext instanceof DefaultResourceLoader) {
219-
Collection<ProtocolResolver> protocolResolvers = ((DefaultResourceLoader) applicationContext)
220-
.getProtocolResolvers();
221-
for (ProtocolResolver protocolResolver : protocolResolvers) {
222-
resourceLoader.addProtocolResolver(protocolResolver);
223-
}
217+
protected final void copyProtocolResolvers(ApplicationContext applicationContext,
218+
ResourceLoader resourceLoader) {
219+
if (applicationContext instanceof DefaultResourceLoader
220+
&& resourceLoader instanceof DefaultResourceLoader) {
221+
copyProtocolResolvers((DefaultResourceLoader) applicationContext,
222+
(DefaultResourceLoader) resourceLoader);
223+
}
224+
}
225+
226+
protected final void copyProtocolResolvers(DefaultResourceLoader source,
227+
DefaultResourceLoader destination) {
228+
for (ProtocolResolver resolver : source.getProtocolResolvers()) {
229+
destination.addProtocolResolver(resolver);
224230
}
225-
return resourceLoader;
226231
}
227232

228233
}
@@ -238,25 +243,21 @@ private static class WebResourcePatternResolverFactory
238243
public ResourcePatternResolver getResourcePatternResolver(
239244
ApplicationContext applicationContext, ResourceLoader resourceLoader) {
240245
if (applicationContext instanceof WebApplicationContext) {
241-
return new ServletContextResourcePatternResolver(resourceLoader == null
242-
? createResourceLoader((WebApplicationContext) applicationContext)
243-
: resourceLoader);
246+
return getResourcePatternResolver(
247+
(WebApplicationContext) applicationContext, resourceLoader);
244248
}
245249
return super.getResourcePatternResolver(applicationContext, resourceLoader);
246250
}
247251

248-
private ResourceLoader createResourceLoader(
249-
WebApplicationContext applicationContext) {
250-
WebApplicationContextResourceLoader resourceLoader = new WebApplicationContextResourceLoader(
251-
applicationContext);
252-
if (applicationContext instanceof DefaultResourceLoader) {
253-
Collection<ProtocolResolver> protocolResolvers = ((DefaultResourceLoader) applicationContext)
254-
.getProtocolResolvers();
255-
for (ProtocolResolver protocolResolver : protocolResolvers) {
256-
resourceLoader.addProtocolResolver(protocolResolver);
257-
}
252+
private ResourcePatternResolver getResourcePatternResolver(
253+
WebApplicationContext applicationContext, ResourceLoader resourceLoader) {
254+
if (resourceLoader == null) {
255+
resourceLoader = new WebApplicationContextResourceLoader(
256+
applicationContext);
257+
copyProtocolResolvers(applicationContext, resourceLoader);
258258
}
259-
return resourceLoader;
259+
return new ServletContextResourcePatternResolver(resourceLoader);
260+
260261
}
261262

262263
}

spring-boot-docs/src/main/asciidoc/deployment.adoc

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -440,65 +440,64 @@ Maven build to run the app.
440440

441441
[[cloud-deployment-gae]]
442442
=== Google Cloud
443-
444-
Google Cloud has several options that could be used to launch Spring Boot applications. The
445-
easiest to get started with is probably App Engine, but you could also find ways to run
446-
Spring Boot in a container with Container Engine, or on a virtual machine using Compute Engine.
447-
448-
To run in App Engine you can create a project in the UI first, which
449-
sets up a unique identifier for you and also HTTP routes. Add a Java
450-
app to the project and leave it empty, then use the
451-
https://cloud.google.com/sdk/downloads[Google Cloud SDK] to push your
443+
Google Cloud has several options that could be used to launch Spring Boot applications.
444+
The easiest to get started with is probably App Engine, but you could also find ways to
445+
run Spring Boot in a container with Container Engine, or on a virtual machine using
446+
Compute Engine.
447+
448+
To run in App Engine you can create a project in the UI first, which sets up a unique
449+
identifier for you and also HTTP routes. Add a Java app to the project and leave it empty,
450+
then use the https://cloud.google.com/sdk/downloads[Google Cloud SDK] to push your
452451
Spring Boot app into that slot from the command line or CI build.
453452

454-
App Engine needs you to create an `app.yaml` file to describe the
455-
resources your app requires. Normally you put this in
456-
`src/min/appengine`, and it looks something like this:
453+
App Engine needs you to create an `app.yaml` file to describe the resources your app
454+
requires. Normally you put this in `src/min/appengine`, and it looks something like this:
457455

458456
[source,yaml,indent=0]
459457
----
460-
service: default
458+
service: default
461459
462-
runtime: java
463-
env: flex
460+
runtime: java
461+
env: flex
464462
465-
runtime_config:
466-
jdk: openjdk8
463+
runtime_config:
464+
jdk: openjdk8
467465
468-
handlers:
469-
- url: /.*
470-
script: this field is required, but ignored
466+
handlers:
467+
- url: /.*
468+
script: this field is required, but ignored
471469
472-
manual_scaling:
473-
instances: 1
470+
manual_scaling:
471+
instances: 1
474472
475-
health_check:
476-
enable_health_check: False
473+
health_check:
474+
enable_health_check: False
477475
478-
env_variables:
479-
ENCRYPT_KEY: your_encryption_key_here
476+
env_variables:
477+
ENCRYPT_KEY: your_encryption_key_here
480478
----
481479

482-
You can deploy the app, for example, with a Maven plugin by simply
483-
adding the project ID to the build configuration:
480+
You can deploy the app, for example, with a Maven plugin by simply adding the project ID
481+
to the build configuration:
484482

485483
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
486484
----
487-
<plugin>
488-
<groupId>com.google.cloud.tools</groupId>
489-
<artifactId>appengine-maven-plugin</artifactId>
490-
<version>1.3.0</version>
491-
<configuration>
492-
<project>myproject</project>
493-
</configuration>
494-
</plugin>
485+
<plugin>
486+
<groupId>com.google.cloud.tools</groupId>
487+
<artifactId>appengine-maven-plugin</artifactId>
488+
<version>1.3.0</version>
489+
<configuration>
490+
<project>myproject</project>
491+
</configuration>
492+
</plugin>
495493
----
496494

497-
Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will fail).
495+
Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will
496+
fail).
498497

499-
NOTE: Google App Engine Classic is tied to the Servlet 2.5 API, so you can't deploy a Spring Application
500-
there without some modifications. See the <<howto.adoc#howto-servlet-2-5, Servlet 2.5 section>>
501-
of this guide.
498+
NOTE: Google App Engine Classic is tied to the Servlet 2.5 API, so you can't deploy a
499+
Spring Application there without some modifications. See the
500+
<<howto.adoc#howto-servlet-2-5, Servlet 2.5 section>> of this guide.
502501

503502

504503

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ key defined via `@PropertySource` will be loaded too late to have any effect on
137137
auto-configuration.
138138

139139

140+
140141
[[howto-build-an-application-context-hierarchy]]
141142
=== Build an ApplicationContext hierarchy (adding a parent or root context)
142143
You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext`

0 commit comments

Comments
 (0)