Merge branch '1.5.x'
This commit is contained in:
@@ -433,65 +433,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.
|
||||
|
||||
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
|
||||
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"]
|
||||
----
|
||||
<plugin>
|
||||
<groupId>com.google.cloud.tools</groupId>
|
||||
<artifactId>appengine-maven-plugin</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<configuration>
|
||||
<project>myproject</project>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.cloud.tools</groupId>
|
||||
<artifactId>appengine-maven-plugin</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<configuration>
|
||||
<project>myproject</project>
|
||||
</configuration>
|
||||
</plugin>
|
||||
----
|
||||
|
||||
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 <<howto.adoc#howto-servlet-2-5, Servlet 2.5 section>>
|
||||
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
|
||||
<<howto.adoc#howto-servlet-2-5, Servlet 2.5 section>> of this guide.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -284,10 +284,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
|
||||
|
||||
@@ -2475,8 +2475,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
|
||||
@@ -6261,7 +6261,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");
|
||||
----
|
||||
|
||||
|
||||
@@ -6274,25 +6274,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]]
|
||||
@@ -6313,17 +6313,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
|
||||
@@ -6334,32 +6334,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(...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user