11[[howto]]
2- = '`How-to`' guides
2+ = '`How-to`' guides
33
44[partintro]
55--
@@ -12,7 +12,7 @@ http://stackoverflow.com/tags/spring-boot[stackoverflow.com] to see if someone h
1212already provided an answer; this is also a great place to ask new questions (please use
1313the `spring-boot` tag).
1414
15- We're also more than happy to extend this section; If you want to add a '`how-to`' you
15+ We're also more than happy to extend this section; If you want to add a '`how-to`' you
1616can send us a {github-code}[pull request].
1717--
1818
@@ -25,7 +25,7 @@ can send us a {github-code}[pull request].
2525
2626[[howto-troubleshoot-auto-configuration]]
2727=== Troubleshoot auto-configuration
28- The Spring Boot auto-configuration tries its best to '`do the right thing`' , but
28+ The Spring Boot auto-configuration tries its best to '`do the right thing`', but
2929sometimes things fail and it can be hard to tell why.
3030
3131There is a really useful `AutoConfigurationReport` available in any Spring Boot
@@ -80,15 +80,15 @@ The `SpringApplication` sends some special `ApplicationEvents` to the listeners
8080some before the context is created), and then registers the listeners for events published
8181by the `ApplicationContext` as well. See
8282'<<spring-boot-features.adoc#boot-features-application-events-and-listeners>>' in the
83- '`Spring Boot features`' section for a complete list.
83+ '`Spring Boot features`' section for a complete list.
8484
8585
8686
8787[[howto-build-an-application-context-hierarchy]]
8888=== Build an ApplicationContext hierarchy (adding a parent or root context)
8989You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext`
9090hierarchies. See '<<spring-boot-features.adoc#boot-features-fluent-builder-api>>'
91- in the '`Spring Boot features`' section for more information.
91+ in the '`Spring Boot features`' section for more information.
9292
9393
9494
@@ -136,7 +136,7 @@ underscores (`_`) as well as dashes (`-`) in property names.
136136=== Change the location of external properties of an application
137137By default properties from different sources are added to the Spring `Environment` in a
138138defined order (see '<<spring-boot-features.adoc#boot-features-external-config>>' in
139- the '`Spring Boot features`' section for the exact order).
139+ the '`Spring Boot features`' section for the exact order).
140140
141141A nice way to augment and modify this is to add `@PropertySource` annotations to your
142142application sources. Classes passed to the `SpringApplication` static convenience
@@ -156,7 +156,7 @@ You can also provide System properties (or environment variables) to change the
156156 command line.
157157
158158No matter what you set in the environment, Spring Boot will always load
159- `application.properties` as described above. If YAML is used then files with the '`.yml`'
159+ `application.properties` as described above. If YAML is used then files with the '`.yml`'
160160extension are also added to the list by default.
161161
162162See {sc-spring-boot}/context/config/ConfigFileApplicationListener.{sc-ext}[`ConfigFileApplicationListener`]
@@ -165,7 +165,7 @@ for more detail.
165165
166166
167167[[howto-use-short-command-line-arguments]]
168- === Use '`short`' command line arguments
168+ === Use '`short`' command line arguments
169169Some people like to use (for example) `--port=9000` instead of `--server.port=9000` to
170170set configuration properties on the command line. You can easily enable this by using
171171placeholders in `application.properties`, e.g.
@@ -223,7 +223,7 @@ The example YAML above corresponds to an `application.properties` file
223223----
224224
225225See '<<spring-boot-features.adoc#boot-features-external-config-yaml>>' in
226- the '`Spring Boot features`' section for more information
226+ the '`Spring Boot features`' section for more information
227227about YAML.
228228
229229[[howto-set-active-spring-profiles]]
@@ -250,7 +250,7 @@ but not by the `SpringApplicationBuilder.profiles()` method. Thus the latter Jav
250250be used to augment the profiles without changing the defaults.
251251
252252See '<<spring-boot-features.adoc#boot-features-profiles>>' in
253- the '`Spring Boot features`' section for more information.
253+ the '`Spring Boot features`' section for more information.
254254
255255
256256
@@ -285,8 +285,8 @@ Example:
285285 port: 0
286286----
287287
288- In this example the default port is 9000, but if the Spring profile '`development`' is
289- active then the port is 9001, and if '`production`' is active then it is 0.
288+ In this example the default port is 9000, but if the Spring profile '`development`' is
289+ active then the port is 9001, and if '`production`' is active then it is 0.
290290
291291The YAML documents are merged in the order they are encountered (so later values override
292292earlier ones).
@@ -366,7 +366,7 @@ that and be sure that it has initialized is to add a `@Bean` of type
366366out of the event when it is published.
367367
368368A really useful thing to do in is to use `@IntegrationTest` to set `server.port=0`
369- and then inject the actual ('`local`' ) port as a `@Value`. For example:
369+ and then inject the actual ('`local`') port as a `@Value`. For example:
370370
371371[source,java,indent=0,subs="verbatim,quotes,attributes"]
372372----
@@ -772,45 +772,45 @@ added.
772772
773773`WebMvcAutoConfiguration` adds the following `ViewResolvers` to your context:
774774
775- * An `InternalResourceViewResolver` with bean id '`defaultViewResolver`' . This one locates
775+ * An `InternalResourceViewResolver` with bean id '`defaultViewResolver`'. This one locates
776776 physical resources that can be rendered using the `DefaultServlet` (e.g. static
777777 resources and JSP pages if you are using those). It applies a prefix and a suffix to the
778778 view name and then looks for a physical resource with that path in the servlet context
779779 (defaults are both empty, but accessible for external configuration via
780780 `spring.view.prefix` and `spring.view.suffix`). It can be overridden by providing a
781781 bean of the same type.
782- * A `BeanNameViewResolver` with id '`beanNameViewResolver`' . This is a useful member of the
782+ * A `BeanNameViewResolver` with id '`beanNameViewResolver`'. This is a useful member of the
783783 view resolver chain and will pick up any beans with the same name as the `View` being
784784 resolved. It shouldn't be necessary to override or replace it.
785- * A `ContentNegotiatingViewResolver` with id '`viewResolver`' is only added if there *are*
786- actually beans of type `View` present. This is a '`master`' resolver, delegating to all
787- the others and attempting to find a match to the '`Accept`' HTTP header sent by the
785+ * A `ContentNegotiatingViewResolver` with id '`viewResolver`' is only added if there *are*
786+ actually beans of type `View` present. This is a '`master`' resolver, delegating to all
787+ the others and attempting to find a match to the '`Accept`' HTTP header sent by the
788788 client. There is a useful
789789 https://spring.io/blog/2013/06/03/content-negotiation-using-views[blog about `ContentNegotiatingViewResolver`]
790790 that you might like to study to learn more, and also look at the source code for detail.
791791 You can switch off the auto-configured
792- `ContentNegotiatingViewResolver` by defining a bean named '`viewResolver`' .
792+ `ContentNegotiatingViewResolver` by defining a bean named '`viewResolver`'.
793793* If you use Thymeleaf you will also have a `ThymeleafViewResolver` with id
794- '`thymeleafViewResolver`' . It looks for resources by surrounding the view name with a
794+ '`thymeleafViewResolver`'. It looks for resources by surrounding the view name with a
795795 prefix and suffix (externalized to `spring.thymeleaf.prefix` and
796- `spring.thymeleaf.suffix`, defaults '`classpath:/templates/`' and '`.html`'
796+ `spring.thymeleaf.suffix`, defaults '`classpath:/templates/`' and '`.html`'
797797 respectively). It can be overridden by providing a bean of the same name.
798798* If you use FreeMarker you will also have a `FreeMarkerViewResolver` with id
799- '`freeMarkerViewResolver`' . It looks for resources in a loader path (externalized to
800- `spring.freemarker.templateLoaderPath`, default '`classpath:/templates/`' ) by
799+ '`freeMarkerViewResolver`'. It looks for resources in a loader path (externalized to
800+ `spring.freemarker.templateLoaderPath`, default '`classpath:/templates/`') by
801801 surrounding the view name with a prefix and suffix (externalized to `spring.freemarker.prefix`
802- and `spring.freemarker.suffix`, with empty and '`.ftl`' defaults respectively). It can
802+ and `spring.freemarker.suffix`, with empty and '`.ftl`' defaults respectively). It can
803803 be overridden by providing a bean of the same name.
804804* If you use Groovy templates (actually if groovy-templates is on your classpath) you will
805- also have a `Groovy TemplateViewResolver` with id '`groovyTemplateViewResolver`' . It
805+ also have a `Groovy TemplateViewResolver` with id '`groovyTemplateViewResolver`'. It
806806 looks for resources in a loader path by surrounding the view name with a prefix and
807807 suffix (externalized to `spring.groovy.template.prefix` and
808- `spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`'
808+ `spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`'
809809 respectively). It can be overriden by providing a bean of the same name.
810- * If you use Velocity you will also have a `VelocityViewResolver` with id '`velocityViewResolver`' .
810+ * If you use Velocity you will also have a `VelocityViewResolver` with id '`velocityViewResolver`'.
811811 It looks for resources in a loader path (externalized to `spring.velocity.resourceLoaderPath`,
812- default '`classpath:/templates/`' ) by surrounding the view name with a prefix and suffix
813- (externalized to `spring.velocity.prefix` and `spring.velocity.suffix`, with empty and '`.vm`'
812+ default '`classpath:/templates/`') by surrounding the view name with a prefix and suffix
813+ (externalized to `spring.velocity.prefix` and `spring.velocity.suffix`, with empty and '`.vm`'
814814 defaults respectively). It can be overridden by providing a bean of the same name.
815815
816816Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`WebMvcAutoConfiguration`],
@@ -965,7 +965,7 @@ your own, and bind it to a set of `Environment` properties e.g.
965965----
966966
967967See '<<spring-boot-features.adoc#boot-features-configure-datasource>>' in the
968- '`Spring Boot features`' section and the
968+ '`Spring Boot features`' section and the
969969{sc-spring-boot-autoconfigure}/jdbc/DataSourceAutoConfiguration.{sc-ext}[`DataSourceAutoConfiguration`]
970970class for more details.
971971
@@ -1063,7 +1063,7 @@ for more details.
10631063[[howto-use-custom-entity-manager]]
10641064=== Use a custom EntityManagerFactory
10651065To take full control of the configuration of the `EntityManagerFactory`, you need to add
1066- a `@Bean` named '`entityManagerFactory`' . Spring Boot auto-configuration switches off its
1066+ a `@Bean` named '`entityManagerFactory`'. Spring Boot auto-configuration switches off its
10671067entity manager based on the presence of a bean of that type.
10681068
10691069
@@ -1118,7 +1118,7 @@ might be able to use a JTA transaction manager spanning both.
11181118Spring doesn't require the use of XML to configure the JPA provider, and Spring Boot
11191119assumes you want to take advantage of that feature. If you prefer to use `persistence.xml`
11201120then you need to define your own `@Bean` of type `LocalEntityManagerFactoryBean` (with
1121- id '`entityManagerFactory`' , and set the persistence unit name there.
1121+ id '`entityManagerFactory`', and set the persistence unit name there.
11221122
11231123See
11241124https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java[`JpaBaseConfiguration`]
@@ -1134,7 +1134,7 @@ automatically. If they are both present on the classpath, you might have to do s
11341134configuration to tell Spring Boot which one (or both) you want to create repositories for
11351135you. The most explicit way to do that is to use the standard Spring Data
11361136`@Enable*Repositories` and tell it the location of your `Repository` interfaces
1137- (where '`*`' is '`Jpa`' or '`Mongo`' or both).
1137+ (where '`*`' is '`Jpa`' or '`Mongo`' or both).
11381138
11391139There are also flags `spring.data.*.repositories.enabled` that you can use to switch the
11401140auto-configured repositories on and off in external configuration. This is useful for
@@ -1173,7 +1173,7 @@ values are `none`, `validate`, `update`, `create-drop`. Spring Boot chooses a de
11731173value for you based on whether it thinks your database is embedded (default `create-drop`)
11741174or not (default `none`). An embedded database is detected by looking at the `Connection`
11751175type: `hsqldb`, `h2` and `derby` are embedded, the rest are not. Be careful when switching
1176- from in-memory to a '`real`' database that you don't make assumptions about the existence of
1176+ from in-memory to a '`real`' database that you don't make assumptions about the existence of
11771177the tables and data in the new platform. You either have to set `ddl-auto` explicitly, or
11781178use one of the other mechanisms to initialize the database.
11791179
@@ -1199,7 +1199,7 @@ to start. The script locations can be changed by setting `spring.datasource.sche
11991199
12001200To disable the failfast you can set `spring.datasource.continueOnError=true`. This can be
12011201useful once an application has matured and been deployed a few times, since the scripts
1202- can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
1202+ can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
12031203there, so there would be no need to prevent the application from running, for instance.
12041204
12051205If you want to use the `schema.sql` initialization in a JPA app (with
@@ -1236,7 +1236,7 @@ To automatically run Flyway database migrations on startup, add the
12361236`org.flywaydb:flyway-core` to your classpath.
12371237
12381238The migrations are scripts in the form `V<VERSION>__<NAME>.sql` (with `<VERSION>` an
1239- underscore-separated version, e.g. '`1`' or '`2_1`' ). By default they live in a folder
1239+ underscore-separated version, e.g. '`1`' or '`2_1`'). By default they live in a folder
12401240`classpath:db/migration` but you can modify that using `flyway.locations` (a list). See
12411241the Flyway class from flyway-core for details of available settings like schemas etc. In
12421242addition Spring Boot provides a small set of properties in
@@ -1315,13 +1315,13 @@ For more detail look at the
13151315{sc-spring-boot-actuator}/autoconfigure/ManagementServerProperties.{sc-ext}[`ManagementServerProperties`]
13161316source code and
13171317'<<production-ready-features.adoc#production-ready-customizing-management-server-port>>'
1318- in the '`Production-ready features`' section.
1318+ in the '`Production-ready features`' section.
13191319
13201320
13211321
13221322[[howto-customize-the-whitelabel-error-page]]
1323- === Customize the '`whitelabel`' error page
1324- Spring Boot installs a '`whitelabel`' error page that you will see in browser client if
1323+ === Customize the '`whitelabel`' error page
1324+ Spring Boot installs a '`whitelabel`' error page that you will see in browser client if
13251325you encounter a server error (machine clients consuming JSON and other media types should
13261326see a sensible response with the right error code). To switch it off you can set
13271327`error.whitelabel.enabled=false`, but normally in addition or alternatively to that you
@@ -1530,7 +1530,7 @@ To configure IntelliJ correctly you can use the `idea` Gradle plugin:
15301530NOTE: Intellij must be configured to use the same Java version as the command line Gradle
15311531task and `springloaded` *must* be included as a `buildscript` dependency.
15321532
1533- You can also additionally enable '`Make Project Automatically`' inside Intellij to
1533+ You can also additionally enable '`Make Project Automatically`' inside Intellij to
15341534automatically compile your code whenever a file is saved.
15351535
15361536
@@ -1568,7 +1568,7 @@ third-party dependencies. Overriding versions may cause compatibility issues.
15681568
15691569[[howto-create-an-executable-jar-with-maven]]
15701570=== Create an executable JAR with Maven
1571- The `spring-boot-maven-plugin` can be used to create an executable '`fat`' JAR. If you
1571+ The `spring-boot-maven-plugin` can be used to create an executable '`fat`' JAR. If you
15721572are using the `spring-boot-starter-parent` POM you can simply declare the plugin and
15731573your jars will be repackaged:
15741574
@@ -1617,7 +1617,7 @@ If you want to use your project as a library jar for other projects to depend on
16171617addition have an executable (e.g. demo) version of it, you will want to configure the
16181618build in a slightly different way.
16191619
1620- For Maven the normal JAR plugin and the Spring Boot plugin both have a '`classifier`'
1620+ For Maven the normal JAR plugin and the Spring Boot plugin both have a '`classifier`'
16211621configuration that you can add to create an additional JAR. Example (using the Spring
16221622Boot Starter Parent to manage the plugin versions and other configuration defaults):
16231623
@@ -1637,7 +1637,7 @@ Boot Starter Parent to manage the plugin versions and other configuration defaul
16371637----
16381638
16391639Two jars are produced, the default one, and an executable one using the Boot plugin with
1640- classifier '`exec`' .
1640+ classifier '`exec`'.
16411641
16421642For Gradle users the steps are similar. Example:
16431643
@@ -1658,7 +1658,7 @@ jar support which assumes that the `jruby-complete.jar` is always directly avail
16581658file in its own right.
16591659
16601660To deal with any problematic libraries, you can flag that specific nested jars should be
1661- automatically unpacked to the '`temp folder`' when the executable jar first runs.
1661+ automatically unpacked to the '`temp folder`' when the executable jar first runs.
16621662
16631663For example, to indicate that JRuby should be flagged for unpack using the Maven Plugin
16641664you would add the following configuration:
@@ -1815,7 +1815,7 @@ archive as normal. To make it executable:
18151815. Use the appropriate launcher as a `Main-Class`, e.g. `JarLauncher` for a jar file, and
18161816 specify the other properties it needs as manifest entries, principally a `Start-Class`.
18171817
1818- . Add the runtime dependencies in a nested '`lib`' directory (for a jar) and the
1818+ . Add the runtime dependencies in a nested '`lib`' directory (for a jar) and the
18191819 `provided` (embedded container) dependencies in a nested `lib-provided` directory.
18201820 Remember *not* to compress the entries in the archive.
18211821
@@ -1868,13 +1868,13 @@ after which you can run the application with
18681868Use the `SpringBootServletInitializer` base class, which is picked up by Spring's
18691869Servlet 3.0 support on deployment. Add an extension of that to your project and build a
18701870war file as normal. For more detail, see the
1871- http://spring.io/guides/gs/convert-jar-to-war['`Converting a jar Project to a war`' ] guide
1871+ http://spring.io/guides/gs/convert-jar-to-war['`Converting a jar Project to a war`'] guide
18721872on the spring.io website and the sample below.
18731873
18741874The war file can also be executable if you use the Spring Boot build tools. In that case
18751875the embedded container classes (to launch Tomcat for instance) have to be added to the
18761876war in a `lib-provided` directory. The tools will take care of that as long as the
1877- dependencies are marked as '`provided`' in Maven or Gradle. Here's a Maven example
1877+ dependencies are marked as '`provided`' in Maven or Gradle. Here's a Maven example
18781878{github-code}/spring-boot-samples/spring-boot-sample-traditional/pom.xml[in the Boot Samples].
18791879
18801880
0 commit comments