|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
[[howto]]
|
|
|
|
|
= '`How-to`' guides
|
|
|
|
|
= '`How-to`' guides
|
|
|
|
|
|
|
|
|
|
[partintro]
|
|
|
|
|
--
|
|
|
|
|
@@ -12,7 +12,7 @@ http://stackoverflow.com/tags/spring-boot[stackoverflow.com] to see if someone h
|
|
|
|
|
already provided an answer; this is also a great place to ask new questions (please use
|
|
|
|
|
the `spring-boot` tag).
|
|
|
|
|
|
|
|
|
|
We're also more than happy to extend this section; If you want to add a '`how-to`' you
|
|
|
|
|
We're also more than happy to extend this section; If you want to add a '`how-to`' you
|
|
|
|
|
can send us a {github-code}[pull request].
|
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
@@ -25,7 +25,7 @@ can send us a {github-code}[pull request].
|
|
|
|
|
|
|
|
|
|
[[howto-troubleshoot-auto-configuration]]
|
|
|
|
|
=== Troubleshoot auto-configuration
|
|
|
|
|
The Spring Boot auto-configuration tries its best to '`do the right thing`' , but
|
|
|
|
|
The Spring Boot auto-configuration tries its best to '`do the right thing`', but
|
|
|
|
|
sometimes things fail and it can be hard to tell why.
|
|
|
|
|
|
|
|
|
|
There is a really useful `AutoConfigurationReport` available in any Spring Boot
|
|
|
|
|
@@ -37,8 +37,8 @@ which not) by Spring Boot at runtime.
|
|
|
|
|
Many more questions can be answered by looking at the source code and the javadoc. Some
|
|
|
|
|
rules of thumb:
|
|
|
|
|
|
|
|
|
|
* Look for classes called `\*AutoConfiguration` and read their sources, in particular the
|
|
|
|
|
`@Conditional\*` annotations to find out what features they enable and when. Add
|
|
|
|
|
* Look for classes called `+*AutoConfiguration+` and read their sources, in particular the
|
|
|
|
|
`+@Conditional*+` annotations to find out what features they enable and when. Add
|
|
|
|
|
`--debug` to the command line or a System property `-Ddebug` to get a log on the
|
|
|
|
|
console of all the autoconfiguration decisions that were made in your app. In a running
|
|
|
|
|
Actuator app look at the `autoconfig` endpoint (`/autoconfig' or the JMX equivalent) for
|
|
|
|
|
@@ -80,7 +80,7 @@ The `SpringApplication` sends some special `ApplicationEvents` to the listeners
|
|
|
|
|
some before the context is created), and then registers the listeners for events published
|
|
|
|
|
by the `ApplicationContext` as well. See
|
|
|
|
|
'<<spring-boot-features.adoc#boot-features-application-events-and-listeners>>' in the
|
|
|
|
|
'`Spring Boot features`' section for a complete list.
|
|
|
|
|
'`Spring Boot features`' section for a complete list.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -88,7 +88,7 @@ by the `ApplicationContext` as well. See
|
|
|
|
|
=== Build an ApplicationContext hierarchy (adding a parent or root context)
|
|
|
|
|
You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext`
|
|
|
|
|
hierarchies. See '<<spring-boot-features.adoc#boot-features-fluent-builder-api>>'
|
|
|
|
|
in the '`Spring Boot features`' section for more information.
|
|
|
|
|
in the '`Spring Boot features`' section for more information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -117,7 +117,7 @@ Application code that you want to run as your business logic can be implemented
|
|
|
|
|
=== Externalize the configuration of SpringApplication
|
|
|
|
|
A `SpringApplication` has bean properties (mainly setters) so you can use its Java API as
|
|
|
|
|
you create the application to modify its behavior. Or you can externalize the
|
|
|
|
|
configuration using properties in `spring.main.*`. E.g. in `application.properties` you
|
|
|
|
|
configuration using properties in `+spring.main.*+`. E.g. in `application.properties` you
|
|
|
|
|
might have.
|
|
|
|
|
|
|
|
|
|
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
|
|
|
|
|
@@ -136,7 +136,7 @@ underscores (`_`) as well as dashes (`-`) in property names.
|
|
|
|
|
=== Change the location of external properties of an application
|
|
|
|
|
By default properties from different sources are added to the Spring `Environment` in a
|
|
|
|
|
defined order (see '<<spring-boot-features.adoc#boot-features-external-config>>' in
|
|
|
|
|
the '`Spring Boot features`' section for the exact order).
|
|
|
|
|
the '`Spring Boot features`' section for the exact order).
|
|
|
|
|
|
|
|
|
|
A nice way to augment and modify this is to add `@PropertySource` annotations to your
|
|
|
|
|
application sources. Classes passed to the `SpringApplication` static convenience
|
|
|
|
|
@@ -156,7 +156,7 @@ You can also provide System properties (or environment variables) to change the
|
|
|
|
|
command line.
|
|
|
|
|
|
|
|
|
|
No matter what you set in the environment, Spring Boot will always load
|
|
|
|
|
`application.properties` as described above. If YAML is used then files with the '`.yml`'
|
|
|
|
|
`application.properties` as described above. If YAML is used then files with the '`.yml`'
|
|
|
|
|
extension are also added to the list by default.
|
|
|
|
|
|
|
|
|
|
See {sc-spring-boot}/context/config/ConfigFileApplicationListener.{sc-ext}[`ConfigFileApplicationListener`]
|
|
|
|
|
@@ -165,7 +165,7 @@ for more detail.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[howto-use-short-command-line-arguments]]
|
|
|
|
|
=== Use '`short`' command line arguments
|
|
|
|
|
=== Use '`short`' command line arguments
|
|
|
|
|
Some people like to use (for example) `--port=9000` instead of `--server.port=9000` to
|
|
|
|
|
set configuration properties on the command line. You can easily enable this by using
|
|
|
|
|
placeholders in `application.properties`, e.g.
|
|
|
|
|
@@ -177,8 +177,8 @@ placeholders in `application.properties`, e.g.
|
|
|
|
|
|
|
|
|
|
TIP: If you are inheriting from the `spring-boot-starter-parent` POM, or if have enabled
|
|
|
|
|
maven filtering for the `application.properties` directly, you may want to change the
|
|
|
|
|
default filter token from `${\*}` since it conflicts with those placeholders.
|
|
|
|
|
You can either use `@*@` (i.e. `@maven.token@` instead of `${maven.token}`) or you can
|
|
|
|
|
default filter token from `+${*}+` since it conflicts with those placeholders.
|
|
|
|
|
You can either use `+@*@+` (i.e. `@maven.token@` instead of `${maven.token}`) or you can
|
|
|
|
|
configure the `maven-resources-plugin` to use
|
|
|
|
|
http://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#delimiters[other delimiters].
|
|
|
|
|
|
|
|
|
|
@@ -223,7 +223,7 @@ The example YAML above corresponds to an `application.properties` file
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
See '<<spring-boot-features.adoc#boot-features-external-config-yaml>>' in
|
|
|
|
|
the '`Spring Boot features`' section for more information
|
|
|
|
|
the '`Spring Boot features`' section for more information
|
|
|
|
|
about YAML.
|
|
|
|
|
|
|
|
|
|
[[howto-set-active-spring-profiles]]
|
|
|
|
|
@@ -250,7 +250,7 @@ but not by the `SpringApplicationBuilder.profiles()` method. Thus the latter Jav
|
|
|
|
|
be used to augment the profiles without changing the defaults.
|
|
|
|
|
|
|
|
|
|
See '<<spring-boot-features.adoc#boot-features-profiles>>' in
|
|
|
|
|
the '`Spring Boot features`' section for more information.
|
|
|
|
|
the '`Spring Boot features`' section for more information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -285,8 +285,8 @@ Example:
|
|
|
|
|
port: 0
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
In this example the default port is 9000, but if the Spring profile '`development`' is
|
|
|
|
|
active then the port is 9001, and if '`production`' is active then it is 0.
|
|
|
|
|
In this example the default port is 9000, but if the Spring profile '`development`' is
|
|
|
|
|
active then the port is 9001, and if '`production`' is active then it is 0.
|
|
|
|
|
|
|
|
|
|
The YAML documents are merged in the order they are encountered (so later values override
|
|
|
|
|
earlier ones).
|
|
|
|
|
@@ -366,7 +366,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`. For example:
|
|
|
|
|
and then inject the actual ('`local`') port as a `@Value`. For example:
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
|
|
|
|
----
|
|
|
|
|
@@ -391,7 +391,7 @@ and then inject the actual ('`local`' ) port as a `@Value`. For example:
|
|
|
|
|
|
|
|
|
|
[[howto-configure-ssl]]
|
|
|
|
|
=== Configure SSL
|
|
|
|
|
SSL can be configured declaratively by setting the various `server.ssl.*` properties,
|
|
|
|
|
SSL can be configured declaratively by setting the various `+server.ssl.*+` properties,
|
|
|
|
|
typically in `application.properties` or `application.yml`. For example:
|
|
|
|
|
|
|
|
|
|
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
|
|
|
|
|
@@ -415,7 +415,7 @@ accessible on the filesystem, i.e. it cannot be read from within a jar file.
|
|
|
|
|
Generally you can follow the advice from
|
|
|
|
|
'<<howto-discover-build-in-options-for-external-properties>>' about
|
|
|
|
|
`@ConfigurationProperties` (`ServerProperties` is the main one here), but also look at
|
|
|
|
|
`EmbeddedServletContainerCustomizer` and various Tomcat specific `*Customizers` that you
|
|
|
|
|
`EmbeddedServletContainerCustomizer` and various Tomcat specific `+*Customizers+` that you
|
|
|
|
|
can add in one of those. The Tomcat APIs are quite rich so once you have access to the
|
|
|
|
|
`TomcatEmbeddedServletContainerFactory` you can modify it in a number of ways. Or the
|
|
|
|
|
nuclear option is to add your own `TomcatEmbeddedServletContainerFactory`.
|
|
|
|
|
@@ -835,45 +835,45 @@ added.
|
|
|
|
|
|
|
|
|
|
`WebMvcAutoConfiguration` adds the following `ViewResolvers` to your context:
|
|
|
|
|
|
|
|
|
|
* An `InternalResourceViewResolver` with bean id '`defaultViewResolver`' . This one locates
|
|
|
|
|
* An `InternalResourceViewResolver` with bean id '`defaultViewResolver`'. This one locates
|
|
|
|
|
physical resources that can be rendered using the `DefaultServlet` (e.g. static
|
|
|
|
|
resources and JSP pages if you are using those). It applies a prefix and a suffix to the
|
|
|
|
|
view name and then looks for a physical resource with that path in the servlet context
|
|
|
|
|
(defaults are both empty, but accessible for external configuration via
|
|
|
|
|
`spring.view.prefix` and `spring.view.suffix`). It can be overridden by providing a
|
|
|
|
|
bean of the same type.
|
|
|
|
|
* A `BeanNameViewResolver` with id '`beanNameViewResolver`' . This is a useful member of the
|
|
|
|
|
* A `BeanNameViewResolver` with id '`beanNameViewResolver`'. This is a useful member of the
|
|
|
|
|
view resolver chain and will pick up any beans with the same name as the `View` being
|
|
|
|
|
resolved. It shouldn't be necessary to override or replace it.
|
|
|
|
|
* A `ContentNegotiatingViewResolver` with id '`viewResolver`' is only added if there *are*
|
|
|
|
|
actually beans of type `View` present. This is a '`master`' resolver, delegating to all
|
|
|
|
|
the others and attempting to find a match to the '`Accept`' HTTP header sent by the
|
|
|
|
|
* A `ContentNegotiatingViewResolver` with id '`viewResolver`' is only added if there *are*
|
|
|
|
|
actually beans of type `View` present. This is a '`master`' resolver, delegating to all
|
|
|
|
|
the others and attempting to find a match to the '`Accept`' HTTP header sent by the
|
|
|
|
|
client. There is a useful
|
|
|
|
|
https://spring.io/blog/2013/06/03/content-negotiation-using-views[blog about `ContentNegotiatingViewResolver`]
|
|
|
|
|
that you might like to study to learn more, and also look at the source code for detail.
|
|
|
|
|
You can switch off the auto-configured
|
|
|
|
|
`ContentNegotiatingViewResolver` by defining a bean named '`viewResolver`' .
|
|
|
|
|
`ContentNegotiatingViewResolver` by defining a bean named '`viewResolver`'.
|
|
|
|
|
* If you use Thymeleaf you will also have a `ThymeleafViewResolver` with id
|
|
|
|
|
'`thymeleafViewResolver`' . It looks for resources by surrounding the view name with a
|
|
|
|
|
'`thymeleafViewResolver`'. It looks for resources by surrounding the view name with a
|
|
|
|
|
prefix and suffix (externalized to `spring.thymeleaf.prefix` and
|
|
|
|
|
`spring.thymeleaf.suffix`, defaults '`classpath:/templates/`' and '`.html`'
|
|
|
|
|
`spring.thymeleaf.suffix`, defaults '`classpath:/templates/`' and '`.html`'
|
|
|
|
|
respectively). It can be overridden by providing a bean of the same name.
|
|
|
|
|
* If you use FreeMarker you will also have a `FreeMarkerViewResolver` with id
|
|
|
|
|
'`freeMarkerViewResolver`' . It looks for resources in a loader path (externalized to
|
|
|
|
|
`spring.freemarker.templateLoaderPath`, default '`classpath:/templates/`' ) by
|
|
|
|
|
'`freeMarkerViewResolver`'. It looks for resources in a loader path (externalized to
|
|
|
|
|
`spring.freemarker.templateLoaderPath`, default '`classpath:/templates/`') by
|
|
|
|
|
surrounding the view name with a prefix and suffix (externalized to `spring.freemarker.prefix`
|
|
|
|
|
and `spring.freemarker.suffix`, with empty and '`.ftl`' defaults respectively). It can
|
|
|
|
|
and `spring.freemarker.suffix`, with empty and '`.ftl`' defaults respectively). It can
|
|
|
|
|
be overridden by providing a bean of the same name.
|
|
|
|
|
* If you use Groovy templates (actually if groovy-templates is on your classpath) you will
|
|
|
|
|
also have a `Groovy TemplateViewResolver` with id '`groovyTemplateViewResolver`' . It
|
|
|
|
|
also have a `Groovy TemplateViewResolver` with id '`groovyTemplateViewResolver`'. It
|
|
|
|
|
looks for resources in a loader path by surrounding the view name with a prefix and
|
|
|
|
|
suffix (externalized to `spring.groovy.template.prefix` and
|
|
|
|
|
`spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`'
|
|
|
|
|
`spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`'
|
|
|
|
|
respectively). It can be overriden by providing a bean of the same name.
|
|
|
|
|
* If you use Velocity you will also have a `VelocityViewResolver` with id '`velocityViewResolver`' .
|
|
|
|
|
* If you use Velocity you will also have a `VelocityViewResolver` with id '`velocityViewResolver`'.
|
|
|
|
|
It looks for resources in a loader path (externalized to `spring.velocity.resourceLoaderPath`,
|
|
|
|
|
default '`classpath:/templates/`' ) by surrounding the view name with a prefix and suffix
|
|
|
|
|
(externalized to `spring.velocity.prefix` and `spring.velocity.suffix`, with empty and '`.vm`'
|
|
|
|
|
default '`classpath:/templates/`') by surrounding the view name with a prefix and suffix
|
|
|
|
|
(externalized to `spring.velocity.prefix` and `spring.velocity.suffix`, with empty and '`.vm`'
|
|
|
|
|
defaults respectively). It can be overridden by providing a bean of the same name.
|
|
|
|
|
|
|
|
|
|
Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`WebMvcAutoConfiguration`],
|
|
|
|
|
@@ -1032,7 +1032,7 @@ your own, and bind it to a set of `Environment` properties e.g.
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
See '<<spring-boot-features.adoc#boot-features-configure-datasource>>' in the
|
|
|
|
|
'`Spring Boot features`' section and the
|
|
|
|
|
'`Spring Boot features`' section and the
|
|
|
|
|
{sc-spring-boot-autoconfigure}/jdbc/DataSourceAutoConfiguration.{sc-ext}[`DataSourceAutoConfiguration`]
|
|
|
|
|
class for more details.
|
|
|
|
|
|
|
|
|
|
@@ -1117,7 +1117,7 @@ configuration properties. The most common options to set are:
|
|
|
|
|
(Because of relaxed data binding hyphens or underscores should work equally well as
|
|
|
|
|
property keys.) The `ddl-auto` setting is a special case in that it has different
|
|
|
|
|
defaults depending on whether you are using an embedded database (`create-drop`) or not
|
|
|
|
|
(`none`). In addition all properties in `spring.jpa.properties.*` are passed through as
|
|
|
|
|
(`none`). In addition all properties in `+spring.jpa.properties.*+` are passed through as
|
|
|
|
|
normal JPA properties (with the prefix stripped) when the local `EntityManagerFactory` is
|
|
|
|
|
created.
|
|
|
|
|
|
|
|
|
|
@@ -1130,7 +1130,7 @@ for more details.
|
|
|
|
|
[[howto-use-custom-entity-manager]]
|
|
|
|
|
=== Use a custom EntityManagerFactory
|
|
|
|
|
To take full control of the configuration of the `EntityManagerFactory`, you need to add
|
|
|
|
|
a `@Bean` named '`entityManagerFactory`' . Spring Boot auto-configuration switches off its
|
|
|
|
|
a `@Bean` named '`entityManagerFactory`'. Spring Boot auto-configuration switches off its
|
|
|
|
|
entity manager based on the presence of a bean of that type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1185,7 +1185,7 @@ might be able to use a JTA transaction manager spanning both.
|
|
|
|
|
Spring doesn't require the use of XML to configure the JPA provider, and Spring Boot
|
|
|
|
|
assumes you want to take advantage of that feature. If you prefer to use `persistence.xml`
|
|
|
|
|
then you need to define your own `@Bean` of type `LocalEntityManagerFactoryBean` (with
|
|
|
|
|
id '`entityManagerFactory`' , and set the persistence unit name there.
|
|
|
|
|
id '`entityManagerFactory`', and set the persistence unit name there.
|
|
|
|
|
|
|
|
|
|
See
|
|
|
|
|
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java[`JpaBaseConfiguration`]
|
|
|
|
|
@@ -1200,10 +1200,10 @@ Spring Data JPA and Spring Data Mongo can both create `Repository` implementatio
|
|
|
|
|
automatically. If they are both present on the classpath, you might have to do some extra
|
|
|
|
|
configuration to tell Spring Boot which one (or both) you want to create repositories for
|
|
|
|
|
you. The most explicit way to do that is to use the standard Spring Data
|
|
|
|
|
`@Enable*Repositories` and tell it the location of your `Repository` interfaces
|
|
|
|
|
(where '`*`' is '`Jpa`' or '`Mongo`' or both).
|
|
|
|
|
`+@Enable*Repositories+` and tell it the location of your `Repository` interfaces
|
|
|
|
|
(where '`*`' is '`Jpa`' or '`Mongo`' or both).
|
|
|
|
|
|
|
|
|
|
There are also flags `spring.data.*.repositories.enabled` that you can use to switch the
|
|
|
|
|
There are also flags `+spring.data.*.repositories.enabled+` that you can use to switch the
|
|
|
|
|
auto-configured repositories on and off in external configuration. This is useful for
|
|
|
|
|
instance in case you want to switch off the Mongo repositories and still use the
|
|
|
|
|
auto-configured `MongoTemplate`.
|
|
|
|
|
@@ -1240,7 +1240,7 @@ values are `none`, `validate`, `update`, `create-drop`. Spring Boot chooses a de
|
|
|
|
|
value for you based on whether it thinks your database is embedded (default `create-drop`)
|
|
|
|
|
or not (default `none`). An embedded database is detected by looking at the `Connection`
|
|
|
|
|
type: `hsqldb`, `h2` and `derby` are embedded, the rest are not. Be careful when switching
|
|
|
|
|
from in-memory to a '`real`' database that you don't make assumptions about the existence of
|
|
|
|
|
from in-memory to a '`real`' database that you don't make assumptions about the existence of
|
|
|
|
|
the tables and data in the new platform. You either have to set `ddl-auto` explicitly, or
|
|
|
|
|
use one of the other mechanisms to initialize the database.
|
|
|
|
|
|
|
|
|
|
@@ -1266,7 +1266,7 @@ to start. The script locations can be changed by setting `spring.datasource.sche
|
|
|
|
|
|
|
|
|
|
To disable the failfast you can set `spring.datasource.continueOnError=true`. This can be
|
|
|
|
|
useful once an application has matured and been deployed a few times, since the scripts
|
|
|
|
|
can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
|
|
|
|
|
can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
|
|
|
|
|
there, so there would be no need to prevent the application from running, for instance.
|
|
|
|
|
|
|
|
|
|
If you want to use the `schema.sql` initialization in a JPA app (with
|
|
|
|
|
@@ -1303,7 +1303,7 @@ To automatically run Flyway database migrations on startup, add the
|
|
|
|
|
`org.flywaydb:flyway-core` to your classpath.
|
|
|
|
|
|
|
|
|
|
The migrations are scripts in the form `V<VERSION>__<NAME>.sql` (with `<VERSION>` an
|
|
|
|
|
underscore-separated version, e.g. '`1`' or '`2_1`' ). By default they live in a folder
|
|
|
|
|
underscore-separated version, e.g. '`1`' or '`2_1`'). By default they live in a folder
|
|
|
|
|
`classpath:db/migration` but you can modify that using `flyway.locations` (a list). See
|
|
|
|
|
the Flyway class from flyway-core for details of available settings like schemas etc. In
|
|
|
|
|
addition Spring Boot provides a small set of properties in
|
|
|
|
|
@@ -1382,13 +1382,13 @@ For more detail look at the
|
|
|
|
|
{sc-spring-boot-actuator}/autoconfigure/ManagementServerProperties.{sc-ext}[`ManagementServerProperties`]
|
|
|
|
|
source code and
|
|
|
|
|
'<<production-ready-features.adoc#production-ready-customizing-management-server-port>>'
|
|
|
|
|
in the '`Production-ready features`' section.
|
|
|
|
|
in the '`Production-ready features`' section.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[howto-customize-the-whitelabel-error-page]]
|
|
|
|
|
=== Customize the '`whitelabel`' error page
|
|
|
|
|
Spring Boot installs a '`whitelabel`' error page that you will see in browser client if
|
|
|
|
|
=== Customize the '`whitelabel`' error page
|
|
|
|
|
Spring Boot installs a '`whitelabel`' error page that you will see in browser client if
|
|
|
|
|
you encounter a server error (machine clients consuming JSON and other media types should
|
|
|
|
|
see a sensible response with the right error code). To switch it off you can set
|
|
|
|
|
`error.whitelabel.enabled=false`, but normally in addition or alternatively to that you
|
|
|
|
|
@@ -1413,7 +1413,7 @@ how to register handlers in the servlet container.
|
|
|
|
|
=== Switch off the Spring Boot security configuration
|
|
|
|
|
If you define a `@Configuration` with `@EnableWebSecurity` anywhere in your application
|
|
|
|
|
it will switch off the default webapp security settings in Spring Boot. To tweak the
|
|
|
|
|
defaults try setting properties in `security.*` (see
|
|
|
|
|
defaults try setting properties in `+security.*+` (see
|
|
|
|
|
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
|
|
|
|
|
for details of available settings) and `SECURITY` section of
|
|
|
|
|
<<common-application-properties-security,Common application properties>>.
|
|
|
|
|
@@ -1596,7 +1596,7 @@ To configure IntelliJ correctly you can use the `idea` Gradle plugin:
|
|
|
|
|
NOTE: Intellij must be configured to use the same Java version as the command line Gradle
|
|
|
|
|
task and `springloaded` *must* be included as a `buildscript` dependency.
|
|
|
|
|
|
|
|
|
|
You can also additionally enable '`Make Project Automatically`' inside Intellij to
|
|
|
|
|
You can also additionally enable '`Make Project Automatically`' inside Intellij to
|
|
|
|
|
automatically compile your code whenever a file is saved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1634,7 +1634,7 @@ third-party dependencies. Overriding versions may cause compatibility issues.
|
|
|
|
|
|
|
|
|
|
[[howto-create-an-executable-jar-with-maven]]
|
|
|
|
|
=== Create an executable JAR with Maven
|
|
|
|
|
The `spring-boot-maven-plugin` can be used to create an executable '`fat`' JAR. If you
|
|
|
|
|
The `spring-boot-maven-plugin` can be used to create an executable '`fat`' JAR. If you
|
|
|
|
|
are using the `spring-boot-starter-parent` POM you can simply declare the plugin and
|
|
|
|
|
your jars will be repackaged:
|
|
|
|
|
|
|
|
|
|
@@ -1683,7 +1683,7 @@ If you want to use your project as a library jar for other projects to depend on
|
|
|
|
|
addition have an executable (e.g. demo) version of it, you will want to configure the
|
|
|
|
|
build in a slightly different way.
|
|
|
|
|
|
|
|
|
|
For Maven the normal JAR plugin and the Spring Boot plugin both have a '`classifier`'
|
|
|
|
|
For Maven the normal JAR plugin and the Spring Boot plugin both have a '`classifier`'
|
|
|
|
|
configuration that you can add to create an additional JAR. Example (using the Spring
|
|
|
|
|
Boot Starter Parent to manage the plugin versions and other configuration defaults):
|
|
|
|
|
|
|
|
|
|
@@ -1703,7 +1703,7 @@ Boot Starter Parent to manage the plugin versions and other configuration defaul
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
Two jars are produced, the default one, and an executable one using the Boot plugin with
|
|
|
|
|
classifier '`exec`' .
|
|
|
|
|
classifier '`exec`'.
|
|
|
|
|
|
|
|
|
|
For Gradle users the steps are similar. Example:
|
|
|
|
|
|
|
|
|
|
@@ -1724,7 +1724,7 @@ jar support which assumes that the `jruby-complete.jar` is always directly avail
|
|
|
|
|
file in its own right.
|
|
|
|
|
|
|
|
|
|
To deal with any problematic libraries, you can flag that specific nested jars should be
|
|
|
|
|
automatically unpacked to the '`temp folder`' when the executable jar first runs.
|
|
|
|
|
automatically unpacked to the '`temp folder`' when the executable jar first runs.
|
|
|
|
|
|
|
|
|
|
For example, to indicate that JRuby should be flagged for unpack using the Maven Plugin
|
|
|
|
|
you would add the following configuration:
|
|
|
|
|
@@ -1881,7 +1881,7 @@ archive as normal. To make it executable:
|
|
|
|
|
. Use the appropriate launcher as a `Main-Class`, e.g. `JarLauncher` for a jar file, and
|
|
|
|
|
specify the other properties it needs as manifest entries, principally a `Start-Class`.
|
|
|
|
|
|
|
|
|
|
. Add the runtime dependencies in a nested '`lib`' directory (for a jar) and the
|
|
|
|
|
. Add the runtime dependencies in a nested '`lib`' directory (for a jar) and the
|
|
|
|
|
`provided` (embedded container) dependencies in a nested `lib-provided` directory.
|
|
|
|
|
Remember *not* to compress the entries in the archive.
|
|
|
|
|
|
|
|
|
|
@@ -1934,13 +1934,13 @@ after which you can run the application with
|
|
|
|
|
Use the `SpringBootServletInitializer` base class, which is picked up by Spring's
|
|
|
|
|
Servlet 3.0 support on deployment. Add an extension of that to your project and build a
|
|
|
|
|
war file as normal. For more detail, see the
|
|
|
|
|
http://spring.io/guides/gs/convert-jar-to-war['`Converting a jar Project to a war`' ] guide
|
|
|
|
|
http://spring.io/guides/gs/convert-jar-to-war['`Converting a jar Project to a war`'] guide
|
|
|
|
|
on the spring.io website and the sample below.
|
|
|
|
|
|
|
|
|
|
The war file can also be executable if you use the Spring Boot build tools. In that case
|
|
|
|
|
the embedded container classes (to launch Tomcat for instance) have to be added to the
|
|
|
|
|
war in a `lib-provided` directory. The tools will take care of that as long as the
|
|
|
|
|
dependencies are marked as '`provided`' in Maven or Gradle. Here's a Maven example
|
|
|
|
|
dependencies are marked as '`provided`' in Maven or Gradle. Here's a Maven example
|
|
|
|
|
{github-code}/spring-boot-samples/spring-boot-sample-traditional/pom.xml[in the Boot Samples].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|