Skip to content

Commit fad5ce4

Browse files
author
Phillip Webb
committed
Polish
1 parent 316cb87 commit fad5ce4

File tree

46 files changed

+274
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+274
-251
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ public void onApplicationEvent(ContextClosedEvent event) {
200200
registerContainer(this.applicationContext,
201201
childContext.getEmbeddedServletContainer());
202202
}
203-
catch (RuntimeException e) {
203+
catch (RuntimeException ex) {
204204
// No support currently for deploying a war with management.port=<different>,
205205
// and this is the signature of that happening
206-
if (e instanceof EmbeddedServletContainerException
207-
|| e.getCause() instanceof EmbeddedServletContainerException) {
206+
if (ex instanceof EmbeddedServletContainerException
207+
|| ex.getCause() instanceof EmbeddedServletContainerException) {
208208
logger.warn("Could not start embedded container (management endpoints are still available through JMX)");
209209
}
210210
else {
211-
throw e;
211+
throw ex;
212212
}
213213
}
214214
};

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2014 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.

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public ThymeleafViewResolver thymeleafViewResolver() {
178178
resolver.setTemplateEngine(this.templateEngine);
179179
resolver.setCharacterEncoding(this.environment.getProperty("encoding",
180180
"UTF-8"));
181-
resolver.setContentType(addEncoding(
181+
resolver.setContentType(appendCharset(
182182
this.environment.getProperty("contentType", "text/html"),
183183
resolver.getCharacterEncoding()));
184184
resolver.setExcludedViewNames(this.environment.getProperty(
@@ -191,13 +191,11 @@ public ThymeleafViewResolver thymeleafViewResolver() {
191191
return resolver;
192192
}
193193

194-
private String addEncoding(String type, String charset) {
194+
private String appendCharset(String type, String charset) {
195195
if (type.contains("charset=")) {
196196
return type;
197197
}
198-
else {
199-
return type + ";charset=" + charset;
200-
}
198+
return type + ";charset=" + charset;
201199
}
202200

203201
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static class WebMvcAutoConfigurationAdapter extends WebMvcConfigurerAdapt
143143

144144
@Value("${spring.resources.cachePeriod:}")
145145
private Integer cachePeriod;
146-
146+
147147
@Value("${spring.mvc.locale:}")
148148
private String locale = "";
149149

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityPropertiesTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
public class SecurityPropertiesTests {
3939

4040
private SecurityProperties security = new SecurityProperties();
41+
4142
private RelaxedDataBinder binder = new RelaxedDataBinder(this.security, "security");
4243

4344
@Before

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,22 @@ public void resourceHandlerMappingOverrideAll() throws Exception {
149149
equalTo((Resource) new ClassPathResource("/foo/")));
150150
}
151151

152-
@Test(expected = NoSuchBeanDefinitionException.class)
153152
public void noLocaleResolver() throws Exception {
154153
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
155154
this.context.register(AllResources.class, Config.class,
156155
WebMvcAutoConfiguration.class,
157156
HttpMessageConvertersAutoConfiguration.class,
158157
PropertyPlaceholderAutoConfiguration.class);
159158
this.context.refresh();
159+
this.thrown.expect(NoSuchBeanDefinitionException.class);
160160
this.context.getBean(LocaleResolver.class);
161161
}
162162

163163
@Test
164164
public void overrideLocale() throws Exception {
165165
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
166166
// set fixed locale
167-
EnvironmentTestUtils.addEnvironment(this.context,
168-
"spring.mvc.locale:en_UK");
167+
EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.locale:en_UK");
169168
this.context.register(AllResources.class, Config.class,
170169
WebMvcAutoConfiguration.class,
171170
HttpMessageConvertersAutoConfiguration.class,
@@ -176,11 +175,9 @@ public void overrideLocale() throws Exception {
176175
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
177176
LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
178177
Locale locale = localeResolver.resolveLocale(request);
179-
assertThat(localeResolver,
180-
instanceOf(FixedLocaleResolver.class));
178+
assertThat(localeResolver, instanceOf(FixedLocaleResolver.class));
181179
// test locale resolver uses fixed locale and not user preferred locale
182-
assertThat(locale.toString(),
183-
equalTo("en_UK"));
180+
assertThat(locale.toString(), equalTo("en_UK"));
184181
}
185182

186183
@SuppressWarnings("unchecked")

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ content into your application; rather pick only the properties that you need.
7777
spring.thymeleaf.suffix=.html
7878
spring.thymeleaf.mode=HTML5
7979
spring.thymeleaf.encoding=UTF-8
80-
spring.thymeleaf.contentType=text/html # ;charset=<encoding> is added
80+
spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
8181
spring.thymeleaf.cache=true # set to false for hot refresh
8282
8383
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration])

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ that and be sure that it has initialized is to add a `@Bean` of type
365365
out of the event when it is published.
366366

367367
A really useful thing to do in is to use `@IntegrationTest` to set `server.port=0`
368-
and then inject the actual ("local") port as a `@Value`. Example:
368+
and then inject the actual (``local'') port as a `@Value`. For example:
369369

370370
[source,java,indent=0,subs="verbatim,quotes,attributes"]
371371
----
@@ -377,15 +377,17 @@ and then inject the actual ("local") port as a `@Value`. Example:
377377
378378
@Autowired
379379
EmbeddedWebApplicationContext server;
380-
381-
@Value("${local.server.port}")
380+
381+
@Value("${local.server.port}")
382382
int port;
383383
384384
// ...
385385
386386
}
387387
----
388388

389+
390+
389391
[[howto-configure-tomcat]]
390392
=== Configure Tomcat
391393
Generally you can follow the advice from
@@ -630,22 +632,25 @@ then `http://localhost:8080/thing` will serve a JSON representation of it by def
630632
Sometimes in a browser you might see XML responses (but by default only if `MyThing` was
631633
a JAXB object) because browsers tend to send accept headers that prefer XML.
632634

635+
636+
633637
[[howto-write-an-xml-rest-service]]
634638
=== Write an XML REST service
635639
Since JAXB is in the JDK the same example as we used for JSON would work, as long as the
636640
`MyThing` was annotated as `@XmlRootElement`:
637641

638642
[source,java,indent=0,subs="verbatim,quotes,attributes"]
639643
----
640-
@XmlRootElement
644+
@XmlRootElement
641645
public class MyThing {
642-
private String name;
643-
// .. getters and setters
646+
private String name;
647+
// .. getters and setters
644648
}
645649
----
646650

647-
To get the server to render XML instead of JSON you might have to send
648-
an `Accept: text/xml` header (or use a browser).
651+
To get the server to render XML instead of JSON you might have to send an
652+
`Accept: text/xml` header (or use a browser).
653+
649654

650655

651656
[[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
10091014
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
10101015
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
10111016
classpath). In addition Spring Boot will load a file `schema-${platform}.sql` where
1012-
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
1017+
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
10131018
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
10141019
`postgresql` etc.). Spring Boot enables the failfast feature of the Spring JDBC
10151020
initializer by default, so if the scripts cause exceptions the application will fail

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -740,18 +740,15 @@ if needed.
740740

741741
[[production-ready-error-handling]]
742742
== Error Handling
743+
Spring Boot Actuator provides an `/error` mapping by default that handles all errors in a
744+
sensible way, and it is registered as a ``global'' error page in the servlet container.
745+
For machine clients it will produce a JSON response with details of the error, the HTTP
746+
status and the exception message. For browser clients there is a ``whitelabel'' error
747+
view that renders the same data in HTML format (to customize it just add a `View` that
748+
resolves to ``error'').
743749

744-
Spring Boot Actuator provides an `/error` mapping by default that
745-
handles all errors in a sensible way, and it is registered as a
746-
"global" error page in the servlet container. For machine clients it
747-
will produce a JSON response with details of the error, the HTTP
748-
status and the exception message. For browser clients there is a
749-
"whitelabel" error view that renders the same data in HTML format (to
750-
customize it just add a `View` that resolves to ``error'').
751-
752-
If you want more specific error
753-
pages for some conditions, the embedded servlet containers support a
754-
uniform Java DSL for customizing the error handling. For example:
750+
If you want more specific error pages for some conditions, the embedded servlet containers
751+
support a uniform Java DSL for customizing the error handling. For example:
755752

756753
[source,java,indent=0,subs="verbatim,quotes,attributes"]
757754
----
@@ -772,11 +769,11 @@ uniform Java DSL for customizing the error handling. For example:
772769
}
773770
----
774771

775-
776772
You can also use regular Spring MVC features like http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-exception-handlers[`@ExceptionHandler`
777773
methods] and http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice[`@ControllerAdvice`].
778774

779775

776+
780777
[[production-ready-process-monitoring]]
781778
== Process monitoring
782779
In Spring Boot Actuator you can find `ApplicationPidListener` which creates file
@@ -789,10 +786,11 @@ ways described below.
789786
[[production-ready-process-monitoring-configuration]]
790787
=== Extend configuration
791788
In `META-INF/spring.factories` file you have to activate the listener:
789+
792790
[indent=0]
793791
----
794-
org.springframework.context.ApplicationListener=\
795-
org.springframework.boot.actuate.system.ApplicationPidListener
792+
org.springframework.context.ApplicationListener=\
793+
org.springframework.boot.actuate.system.ApplicationPidListener
796794
----
797795

798796

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,23 @@ default `name`. When running in production, an `application.properties` can be p
231231
outside of your jar that overrides `name`; and for one-off testing, you can launch with
232232
a specific command line switch (e.g. `java -jar app.jar --name="Spring"`).
233233

234-
The `RandomValuePropertySource` is useful for injecting random values
235-
(e.g. into secrets or test cases). It can produce integers, longs or
236-
strings, e.g.
237-
234+
The `RandomValuePropertySource` is useful for injecting random values (e.g. into secrets
235+
or test cases). It can produce integers, longs or strings, e.g.
238236

239237
[source,properties,indent=0]
240238
----
241-
my.secret=${random.value}
242-
my.number=${random.int}
243-
my.bignumber=${random.long}
244-
my.number.less.than.ten=${random.int(10)}
245-
my.number.in.range=${random.int[1024,65536]}
239+
my.secret=${random.value}
240+
my.number=${random.int}
241+
my.bignumber=${random.long}
242+
my.number.less.than.ten=${random.int(10)}
243+
my.number.in.range=${random.int[1024,65536]}
246244
----
247245

248-
The `random.int*` syntax is `OPEN value (,max) CLOSE` where the
249-
`OPEN,CLOSE` are any character and `value,max` are integers. If
250-
`max` is provided then `value` is the minimum value and `max` is the
251-
maximum (exclusive).
246+
The `random.int*` syntax is `OPEN value (,max) CLOSE` where the `OPEN,CLOSE` are any
247+
character and `value,max` are integers. If `max` is provided then `value` is the minimum
248+
value and `max` is the maximum (exclusive).
249+
250+
252251

253252
[[boot-features-external-config-command-line-args]]
254253
=== Accessing command line properties
@@ -372,15 +371,15 @@ Would be transformed into these properties:
372371
environments.prod.name=My Cool App
373372
----
374373

375-
YAML lists are represented as property keys with `[index]` dereferencers,
374+
YAML lists are represented as property keys with `[index]` dereferencers,
376375
for example this YAML:
377376

378377
[source,yaml,indent=0]
379378
----
380379
my:
381-
servers:
382-
- dev.bar.com
383-
- foo.bar.com
380+
servers:
381+
- dev.bar.com
382+
- foo.bar.com
384383
----
385384

386385
Would be transformed into these properties:
@@ -391,22 +390,25 @@ Would be transformed into these properties:
391390
my.servers[1]=foo.bar.com
392391
----
393392

394-
To bind to properties like that using the Spring `DataBinder`
395-
utilities (which is what `@ConfigurationProperties` does) you need to
396-
have a property in the target bean of type `java.util.List` (or `Set`)
397-
and you either need to provide a setter, or initialize it with a
398-
mutable value, e.g. this will bind to the properties above
393+
To bind to properties like that using the Spring `DataBinder` utilities (which is what
394+
`@ConfigurationProperties` does) you need to have a property in the target bean of type
395+
`java.util.List` (or `Set`) and you either need to provide a setter, or initialize it
396+
with a mutable value, e.g. this will bind to the properties above
399397

400398
[source,java,indent=0]
401399
----
402-
@ConfigurationProperties(prefix="my")
403-
public class Config {
404-
private List<String> servers = new ArrayList<String>();
405-
public List<String> getServers() { return this.servers; }
406-
}
400+
@ConfigurationProperties(prefix="my")
401+
public class Config {
402+
private List<String> servers = new ArrayList<String>();
403+
404+
public List<String> getServers() {
405+
return this.servers;
406+
}
407+
}
407408
----
408409

409410

411+
410412
[[boot-features-external-config-exposing-yaml-to-spring]]
411413
==== Exposing YAML as properties in the Spring Environment
412414
The `YamlPropertySourceLoader` class can be used to expose YAML as a `PropertySource`
@@ -1570,9 +1572,10 @@ interaction. For Example:
15701572
}
15711573
----
15721574

1573-
To change the port you can add environment properties to
1574-
`@IntegrationTest` as colon- or equals-separated name-value pairs,
1575-
e.g. `@IntegrationTest("server.port:9000")`.
1575+
To change the port you can add environment properties to `@IntegrationTest` as colon- or
1576+
equals-separated name-value pairs, e.g. `@IntegrationTest("server.port:9000")`.
1577+
1578+
15761579

15771580
[[boot-features-test-utilities]]
15781581
=== Test utilities

0 commit comments

Comments
 (0)