Polish
This commit is contained in:
@@ -77,7 +77,7 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.thymeleaf.suffix=.html
|
||||
spring.thymeleaf.mode=HTML5
|
||||
spring.thymeleaf.encoding=UTF-8
|
||||
spring.thymeleaf.contentType=text/html # ;charset=<encoding> is added
|
||||
spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
|
||||
spring.thymeleaf.cache=true # set to false for hot refresh
|
||||
|
||||
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration])
|
||||
|
||||
@@ -365,7 +365,7 @@ that and be sure that it has initialized is to add a `@Bean` of type
|
||||
out of the event when it is published.
|
||||
|
||||
A really useful thing to do in is to use `@IntegrationTest` to set `server.port=0`
|
||||
and then inject the actual ("local") port as a `@Value`. Example:
|
||||
and then inject the actual (``local'') port as a `@Value`. For example:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
@@ -377,8 +377,8 @@ and then inject the actual ("local") port as a `@Value`. Example:
|
||||
|
||||
@Autowired
|
||||
EmbeddedWebApplicationContext server;
|
||||
|
||||
@Value("${local.server.port}")
|
||||
|
||||
@Value("${local.server.port}")
|
||||
int port;
|
||||
|
||||
// ...
|
||||
@@ -386,6 +386,8 @@ and then inject the actual ("local") port as a `@Value`. Example:
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[howto-configure-tomcat]]
|
||||
=== Configure Tomcat
|
||||
Generally you can follow the advice from
|
||||
@@ -630,6 +632,8 @@ then `http://localhost:8080/thing` will serve a JSON representation of it by def
|
||||
Sometimes in a browser you might see XML responses (but by default only if `MyThing` was
|
||||
a JAXB object) because browsers tend to send accept headers that prefer XML.
|
||||
|
||||
|
||||
|
||||
[[howto-write-an-xml-rest-service]]
|
||||
=== Write an XML REST service
|
||||
Since JAXB is in the JDK the same example as we used for JSON would work, as long as the
|
||||
@@ -637,15 +641,16 @@ Since JAXB is in the JDK the same example as we used for JSON would work, as lon
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
@XmlRootElement
|
||||
@XmlRootElement
|
||||
public class MyThing {
|
||||
private String name;
|
||||
// .. getters and setters
|
||||
private String name;
|
||||
// .. getters and setters
|
||||
}
|
||||
----
|
||||
|
||||
To get the server to render XML instead of JSON you might have to send
|
||||
an `Accept: text/xml` header (or use a browser).
|
||||
To get the server to render XML instead of JSON you might have to send an
|
||||
`Accept: text/xml` header (or use a browser).
|
||||
|
||||
|
||||
|
||||
[[howto-customize-the-jackson-objectmapper]]
|
||||
@@ -1009,7 +1014,7 @@ not something you want to be on the classpath in production. It is a Hibernate f
|
||||
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
|
||||
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
|
||||
classpath). In addition Spring Boot will load a file `schema-${platform}.sql` where
|
||||
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
|
||||
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
|
||||
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
|
||||
`postgresql` etc.). Spring Boot enables the failfast feature of the Spring JDBC
|
||||
initializer by default, so if the scripts cause exceptions the application will fail
|
||||
|
||||
@@ -740,18 +740,15 @@ if needed.
|
||||
|
||||
[[production-ready-error-handling]]
|
||||
== Error Handling
|
||||
Spring Boot Actuator provides an `/error` mapping by default that handles all errors in a
|
||||
sensible way, and it is registered as a ``global'' error page in the servlet container.
|
||||
For machine clients it will produce a JSON response with details of the error, the HTTP
|
||||
status and the exception message. For browser clients there is a ``whitelabel'' error
|
||||
view that renders the same data in HTML format (to customize it just add a `View` that
|
||||
resolves to ``error'').
|
||||
|
||||
Spring Boot Actuator provides an `/error` mapping by default that
|
||||
handles all errors in a sensible way, and it is registered as a
|
||||
"global" error page in the servlet container. For machine clients it
|
||||
will produce a JSON response with details of the error, the HTTP
|
||||
status and the exception message. For browser clients there is a
|
||||
"whitelabel" error view that renders the same data in HTML format (to
|
||||
customize it just add a `View` that resolves to ``error'').
|
||||
|
||||
If you want more specific error
|
||||
pages for some conditions, the embedded servlet containers support a
|
||||
uniform Java DSL for customizing the error handling. For example:
|
||||
If you want more specific error pages for some conditions, the embedded servlet containers
|
||||
support a uniform Java DSL for customizing the error handling. For example:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
@@ -772,11 +769,11 @@ uniform Java DSL for customizing the error handling. For example:
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
You can also use regular Spring MVC features like http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-exception-handlers[`@ExceptionHandler`
|
||||
methods] and http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice[`@ControllerAdvice`].
|
||||
|
||||
|
||||
|
||||
[[production-ready-process-monitoring]]
|
||||
== Process monitoring
|
||||
In Spring Boot Actuator you can find `ApplicationPidListener` which creates file
|
||||
@@ -789,10 +786,11 @@ ways described below.
|
||||
[[production-ready-process-monitoring-configuration]]
|
||||
=== Extend configuration
|
||||
In `META-INF/spring.factories` file you have to activate the listener:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.boot.actuate.system.ApplicationPidListener
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.boot.actuate.system.ApplicationPidListener
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -231,24 +231,23 @@ default `name`. When running in production, an `application.properties` can be p
|
||||
outside of your jar that overrides `name`; and for one-off testing, you can launch with
|
||||
a specific command line switch (e.g. `java -jar app.jar --name="Spring"`).
|
||||
|
||||
The `RandomValuePropertySource` is useful for injecting random values
|
||||
(e.g. into secrets or test cases). It can produce integers, longs or
|
||||
strings, e.g.
|
||||
|
||||
The `RandomValuePropertySource` is useful for injecting random values (e.g. into secrets
|
||||
or test cases). It can produce integers, longs or strings, e.g.
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
my.secret=${random.value}
|
||||
my.number=${random.int}
|
||||
my.bignumber=${random.long}
|
||||
my.number.less.than.ten=${random.int(10)}
|
||||
my.number.in.range=${random.int[1024,65536]}
|
||||
my.secret=${random.value}
|
||||
my.number=${random.int}
|
||||
my.bignumber=${random.long}
|
||||
my.number.less.than.ten=${random.int(10)}
|
||||
my.number.in.range=${random.int[1024,65536]}
|
||||
----
|
||||
|
||||
The `random.int*` syntax is `OPEN value (,max) CLOSE` where the
|
||||
`OPEN,CLOSE` are any character and `value,max` are integers. If
|
||||
`max` is provided then `value` is the minimum value and `max` is the
|
||||
maximum (exclusive).
|
||||
The `random.int*` syntax is `OPEN value (,max) CLOSE` where the `OPEN,CLOSE` are any
|
||||
character and `value,max` are integers. If `max` is provided then `value` is the minimum
|
||||
value and `max` is the maximum (exclusive).
|
||||
|
||||
|
||||
|
||||
[[boot-features-external-config-command-line-args]]
|
||||
=== Accessing command line properties
|
||||
@@ -372,15 +371,15 @@ Would be transformed into these properties:
|
||||
environments.prod.name=My Cool App
|
||||
----
|
||||
|
||||
YAML lists are represented as property keys with `[index]` dereferencers,
|
||||
YAML lists are represented as property keys with `[index]` dereferencers,
|
||||
for example this YAML:
|
||||
|
||||
[source,yaml,indent=0]
|
||||
----
|
||||
my:
|
||||
servers:
|
||||
- dev.bar.com
|
||||
- foo.bar.com
|
||||
servers:
|
||||
- dev.bar.com
|
||||
- foo.bar.com
|
||||
----
|
||||
|
||||
Would be transformed into these properties:
|
||||
@@ -391,22 +390,25 @@ Would be transformed into these properties:
|
||||
my.servers[1]=foo.bar.com
|
||||
----
|
||||
|
||||
To bind to properties like that using the Spring `DataBinder`
|
||||
utilities (which is what `@ConfigurationProperties` does) you need to
|
||||
have a property in the target bean of type `java.util.List` (or `Set`)
|
||||
and you either need to provide a setter, or initialize it with a
|
||||
mutable value, e.g. this will bind to the properties above
|
||||
To bind to properties like that using the Spring `DataBinder` utilities (which is what
|
||||
`@ConfigurationProperties` does) you need to have a property in the target bean of type
|
||||
`java.util.List` (or `Set`) and you either need to provide a setter, or initialize it
|
||||
with a mutable value, e.g. this will bind to the properties above
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@ConfigurationProperties(prefix="my")
|
||||
public class Config {
|
||||
private List<String> servers = new ArrayList<String>();
|
||||
public List<String> getServers() { return this.servers; }
|
||||
}
|
||||
@ConfigurationProperties(prefix="my")
|
||||
public class Config {
|
||||
private List<String> servers = new ArrayList<String>();
|
||||
|
||||
public List<String> getServers() {
|
||||
return this.servers;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[boot-features-external-config-exposing-yaml-to-spring]]
|
||||
==== Exposing YAML as properties in the Spring Environment
|
||||
The `YamlPropertySourceLoader` class can be used to expose YAML as a `PropertySource`
|
||||
@@ -1570,9 +1572,10 @@ interaction. For Example:
|
||||
}
|
||||
----
|
||||
|
||||
To change the port you can add environment properties to
|
||||
`@IntegrationTest` as colon- or equals-separated name-value pairs,
|
||||
e.g. `@IntegrationTest("server.port:9000")`.
|
||||
To change the port you can add environment properties to `@IntegrationTest` as colon- or
|
||||
equals-separated name-value pairs, e.g. `@IntegrationTest("server.port:9000")`.
|
||||
|
||||
|
||||
|
||||
[[boot-features-test-utilities]]
|
||||
=== Test utilities
|
||||
|
||||
Reference in New Issue
Block a user