Skip to content

Commit eb17aa0

Browse files
committed
Merge branch '1.5.x'
2 parents 6bc498c + aa57ca7 commit eb17aa0

File tree

24 files changed

+189
-173
lines changed

24 files changed

+189
-173
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
@@ -171,20 +171,13 @@ private Health getHealth(HttpServletRequest request, Principal principal) {
171171

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

190183
protected boolean exposeHealthDetails(HttpServletRequest request,
@@ -234,6 +227,14 @@ static class CachedHealth {
234227
this.creationTime = creationTime;
235228
}
236229

230+
public boolean isStale(long accessTime, long timeToLive) {
231+
return (accessTime - this.creationTime) >= timeToLive;
232+
}
233+
234+
public Health getHealth() {
235+
return this.health;
236+
}
237+
237238
}
238239

239240
}

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
@@ -106,8 +106,8 @@ protected static class ClientContextConfiguration {
106106

107107
private final AccessTokenRequest accessTokenRequest;
108108

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

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
@@ -92,7 +92,7 @@ private String[] appendSlashIfNecessary(String[] staticLocations) {
9292
String[] normalized = new String[staticLocations.length];
9393
for (int i = 0; i < staticLocations.length; i++) {
9494
String location = staticLocations[i];
95-
normalized[i] = location.endsWith("/") ? location : location + "/";
95+
normalized[i] = (location.endsWith("/") ? location : location + "/");
9696
}
9797
return normalized;
9898
}

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
@@ -433,65 +433,64 @@ Maven build to run the app.
433433

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

447-
App Engine needs you to create an `app.yaml` file to describe the
448-
resources your app requires. Normally you put this in
449-
`src/min/appengine`, and it looks something like this:
446+
App Engine needs you to create an `app.yaml` file to describe the resources your app
447+
requires. Normally you put this in `src/min/appengine`, and it looks something like this:
450448

451449
[source,yaml,indent=0]
452450
----
453-
service: default
451+
service: default
454452
455-
runtime: java
456-
env: flex
453+
runtime: java
454+
env: flex
457455
458-
runtime_config:
459-
jdk: openjdk8
456+
runtime_config:
457+
jdk: openjdk8
460458
461-
handlers:
462-
- url: /.*
463-
script: this field is required, but ignored
459+
handlers:
460+
- url: /.*
461+
script: this field is required, but ignored
464462
465-
manual_scaling:
466-
instances: 1
463+
manual_scaling:
464+
instances: 1
467465
468-
health_check:
469-
enable_health_check: False
466+
health_check:
467+
enable_health_check: False
470468
471-
env_variables:
472-
ENCRYPT_KEY: your_encryption_key_here
469+
env_variables:
470+
ENCRYPT_KEY: your_encryption_key_here
473471
----
474472

475-
You can deploy the app, for example, with a Maven plugin by simply
476-
adding the project ID to the build configuration:
473+
You can deploy the app, for example, with a Maven plugin by simply adding the project ID
474+
to the build configuration:
477475

478476
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
479477
----
480-
<plugin>
481-
<groupId>com.google.cloud.tools</groupId>
482-
<artifactId>appengine-maven-plugin</artifactId>
483-
<version>1.3.0</version>
484-
<configuration>
485-
<project>myproject</project>
486-
</configuration>
487-
</plugin>
478+
<plugin>
479+
<groupId>com.google.cloud.tools</groupId>
480+
<artifactId>appengine-maven-plugin</artifactId>
481+
<version>1.3.0</version>
482+
<configuration>
483+
<project>myproject</project>
484+
</configuration>
485+
</plugin>
488486
----
489487

490-
Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will fail).
488+
Then deploy with `mvn appengine:deploy` (if you need to authenticate first the build will
489+
fail).
491490

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

496495

497496

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)