Merge pull requests #10892, #10893, #10896, #10897 from Buzzardo

* pr/10892:
  Format production-ready-features.adoc to 90 chars
  Format spring-boot-features.adoc to 90 chars
  Format using-spring-boot.adoc to 90 chars
  Format getting-started.adoc to 90 chars
pull/10901/merge
Phillip Webb 7 years ago
commit 200eb8f5b5

@ -4,19 +4,20 @@
[partintro]
--
If you are getting started with Spring Boot, or "Spring" in general, start by reading
this section. It answers the basic "`what?`", "`how?`" and "`why?`" questions. It includes
an introduction to Spring Boot, along with installation instructions.
We then walk you through building your first Spring Boot application, discussing some core
this section. It answers the basic "`what?`", "`how?`" and "`why?`" questions. It
includes an introduction to Spring Boot, along with installation instructions. We then
walk you through building your first Spring Boot application, discussing some core
principles as we go.
--
[[getting-started-introducing-spring-boot]]
== Introducing Spring Boot
Spring Boot makes it easy to create stand-alone, production-grade Spring based
Applications that you can run. We take an opinionated view of the Spring
platform and third-party libraries, so that you can get started with minimum fuss. Most
Spring Boot applications need very little Spring configuration.
Applications that you can run. We take an opinionated view of the Spring platform and
third-party libraries, so that you can get started with minimum fuss. Most Spring Boot
applications need very little Spring configuration.
You can use Spring Boot to create Java applications that can be started by using
`java -jar` or more traditional war deployments. We also provide a command line tool that
@ -38,8 +39,9 @@ configuration).
[[getting-started-system-requirements]]
== System Requirements
Spring Boot {spring-boot-version} requires http://www.java.com[Java 8] and Spring
Framework {spring-version} or above. Explicit build support is provided for Maven
3.2+, and Gradle 4.
Framework {spring-version} or above. Explicit build support is provided for Maven 3.2+
and Gradle 4.
[[getting-started-system-requirements-servlet-containers]]
@ -74,8 +76,8 @@ begin, you should check your current Java installation by using the following co
$ java -version
----
If you are new to Java development or if you want to experiment with Spring Boot,
you might want to try the <<getting-started-installing-the-cli, Spring Boot CLI>> (Command
If you are new to Java development or if you want to experiment with Spring Boot, you
might want to try the <<getting-started-installing-the-cli, Spring Boot CLI>> (Command
Line Interface) first, otherwise, read on for "`classic`" installation instructions.
@ -85,28 +87,28 @@ Line Interface) first, otherwise, read on for "`classic`" installation instructi
You can use Spring Boot in the same way as any standard Java library. To do so, include
the appropriate `+spring-boot-*.jar+` files on your classpath. Spring Boot does not
require any special tools integration, so you can use any IDE or text editor. Also, there
is nothing special about a Spring Boot application, so you can run and debug a Spring Boot
application as you would any other Java program.
is nothing special about a Spring Boot application, so you can run and debug a Spring
Boot application as you would any other Java program.
Although you _could_ copy Spring Boot jars, we generally recommend that you use a
build tool that supports dependency management (such as Maven or Gradle).
Although you _could_ copy Spring Boot jars, we generally recommend that you use a build
tool that supports dependency management (such as Maven or Gradle).
[[getting-started-maven-installation]]
==== Maven Installation
Spring Boot is compatible with Apache Maven 3.2 or above. If you do not already have Maven
installed, you can follow the instructions at http://maven.apache.org.
Spring Boot is compatible with Apache Maven 3.2 or above. If you do not already have
Maven installed, you can follow the instructions at http://maven.apache.org.
TIP: On many operating systems, Maven can be installed with a package manager. If you
use OSX Homebrew, try `brew install maven`. Ubuntu users can run
TIP: On many operating systems, Maven can be installed with a package manager. If you use
OSX Homebrew, try `brew install maven`. Ubuntu users can run
`sudo apt-get install maven`. Windows users with Chocolatey can run `choco install maven`
from an elevated (administrator) prompt.
Spring Boot dependencies use the `org.springframework.boot` `groupId`. Typically, your
Maven POM file inherits from the `spring-boot-starter-parent` project and declares
dependencies to one or more <<using-spring-boot.adoc#using-boot-starter,
"`Starters`">>. Spring Boot also provides an optional
dependencies to one or more <<using-spring-boot.adoc#using-boot-starter,"`Starters`">>.
Spring Boot also provides an optional
<<build-tool-plugins.adoc#build-tool-plugins-maven-plugin, Maven plugin>> to create
executable jars.
@ -176,9 +178,9 @@ endif::[]
</project>
----
TIP: The `spring-boot-starter-parent` is a great way to use Spring Boot, but it might
not be suitable all of the time. Sometimes you may need to inherit from a different
parent POM, or you might not like our default settings. In those cases, see
TIP: The `spring-boot-starter-parent` is a great way to use Spring Boot, but it might not
be suitable all of the time. Sometimes you may need to inherit from a different parent
POM, or you might not like our default settings. In those cases, see
<<using-boot-maven-without-a-parent>> for an alternative solution that uses an `import`
scope.
@ -199,11 +201,11 @@ jars.
.Gradle Wrapper
****
The Gradle Wrapper provides a nice way of "`obtaining`" Gradle when you need to build a
project. It is a small script and library that you commit alongside your code to bootstrap
the build process. See {gradle-user-guide}/gradle_wrapper.html for details.
project. It is a small script and library that you commit alongside your code to
bootstrap the build process. See {gradle-user-guide}/gradle_wrapper.html for details.
****
Here is a typical `build.gradle` file:
The following example shows a typical `build.gradle` file:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
@ -257,8 +259,8 @@ The Spring Boot CLI (Command Line Interface) is a command line tool that you can
quickly prototype with Spring. It lets you run http://groovy-lang.org/[Groovy] scripts,
which means that you have a familiar Java-like syntax without so much boilerplate code.
You do not need to use the CLI to work with Spring Boot, but it is definitely the quickest
way to get a Spring application off the ground.
You do not need to use the CLI to work with Spring Boot, but it is definitely the
quickest way to get a Spring application off the ground.
@ -269,10 +271,12 @@ You can download the Spring CLI distribution from the Spring software repository
* http://repo.spring.io/{spring-boot-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.zip[spring-boot-cli-{spring-boot-version}-bin.zip]
* http://repo.spring.io/{spring-boot-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.tar.gz[spring-boot-cli-{spring-boot-version}-bin.tar.gz]
Cutting edge http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/[snapshot
Cutting edge
http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/[snapshot
distributions] are also available.
Once downloaded, follow the {github-raw}/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt[INSTALL.txt]
Once downloaded, follow the
{github-raw}/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt[INSTALL.txt]
instructions from the unpacked archive. In summary, there is a `spring` script
(`spring.bat` for Windows) in a `bin/` directory in the `.zip` file. Alternatively, you
can use `java -jar` with the `.jar` file (the script helps you to be sure that the
@ -282,9 +286,10 @@ classpath is set correctly).
[[getting-started-sdkman-cli-installation]]
==== Installation with SDKMAN!
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of
various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from http://sdkman.io and install Spring Boot by using the following commands:
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions
of various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from http://sdkman.io and install Spring Boot by using the following
commands:
[indent=0,subs="verbatim,quotes,attributes"]
----
@ -293,8 +298,8 @@ Get SDKMAN! from http://sdkman.io and install Spring Boot by using the following
Spring Boot v{spring-boot-version}
----
If you are developing features for the CLI and want easy access to the version you
built, use the following commands:
If you are developing features for the CLI and want easy access to the version you built,
use the following commands:
[indent=0,subs="verbatim,quotes,attributes"]
----
@ -304,9 +309,9 @@ built, use the following commands:
Spring CLI v{spring-boot-version}
----
The preceding instructions install a local instance of `spring` called the `dev` instance.
It points at your target build location, so every time you rebuild Spring
Boot, `spring` is up-to-date.
The preceding instructions install a local instance of `spring` called the `dev`
instance. It points at your target build location, so every time you rebuild Spring Boot,
`spring` is up-to-date.
You can see it by running the following command:
@ -331,8 +336,8 @@ You can see it by running the following command:
[[getting-started-homebrew-cli-installation]]
==== OSX Homebrew Installation
If you are on a Mac and use http://brew.sh/[Homebrew], you can install
the Spring Boot CLI by using the following commands:
If you are on a Mac and use http://brew.sh/[Homebrew], you can install the Spring Boot
CLI by using the following commands:
[indent=0]
----
@ -342,15 +347,15 @@ the Spring Boot CLI by using the following commands:
Homebrew installs `spring` to `/usr/local/bin`.
NOTE: If you do not see the formula, your installation of brew might be out-of-date.
In that case, run `brew update` and try again.
NOTE: If you do not see the formula, your installation of brew might be out-of-date. In
that case, run `brew update` and try again.
[[getting-started-macports-cli-installation]]
==== MacPorts Installation
If you are on a Mac and use http://www.macports.org/[MacPorts], you can
install the Spring Boot CLI by using the following command:
If you are on a Mac and use http://www.macports.org/[MacPorts], you can install the
Spring Boot CLI by using the following command:
[indent=0]
----
@ -361,8 +366,8 @@ install the Spring Boot CLI by using the following command:
[[getting-started-cli-command-line-completion]]
==== Command-line Completion
The Spring Boot CLI includes scripts that provide command completion for
the http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29[BASH] and
The Spring Boot CLI includes scripts that provide command completion for the
http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29[BASH] and
http://en.wikipedia.org/wiki/Zsh[zsh] shells. You can `source` the script (also named
`spring`) in any shell or put it in your personal or system-wide bash completion
initialization. On a Debian system, the system-wide scripts are in
@ -384,8 +389,8 @@ completion scripts are automatically registered with your shell.
[[getting-started-cli-example]]
==== Quick-start Spring CLI Example
You can use the following web application to test your installation. To start, create
a file called `app.groovy`, as follows:
You can use the following web application to test your installation. To start, create a
file called `app.groovy`, as follows:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
----
@ -407,8 +412,8 @@ Then run it from a shell, as follows:
$ spring run app.groovy
----
NOTE: The first run of your application is slow, as dependencies are
downloaded. Subsequent runs are much quicker.
NOTE: The first run of your application is slow, as dependencies are downloaded.
Subsequent runs are much quicker.
Open http://localhost:8080 in your favorite web browser. You should see the following
output:
@ -423,13 +428,13 @@ output:
[[getting-started-upgrading-from-an-earlier-version]]
=== Upgrading from an Earlier Version of Spring Boot
If you are upgrading from an earlier release of Spring Boot check the "`release notes`"
hosted on the {github-wiki}[project wiki]. You'll find upgrade instructions along with
a list of "`new and noteworthy`" features for each release.
hosted on the {github-wiki}[project wiki]. You'll find upgrade instructions along with a
list of "`new and noteworthy`" features for each release.
To upgrade an existing CLI installation use the appropriate package manager command
(for example `brew upgrade`) or, if you manually installed the CLI, follow the
<<getting-started-manual-cli-installation, standard instructions>> remembering to
update your `PATH` environment variable to remove any older references.
To upgrade an existing CLI installation use the appropriate package manager command (for
example, `brew upgrade`) or, if you manually installed the CLI, follow the
<<getting-started-manual-cli-installation, standard instructions>> remembering to update
your `PATH` environment variable to remove any older references.
@ -441,14 +446,15 @@ most IDEs support it.
[TIP]
====
The http://spring.io[spring.io] web site contains many "`Getting Started`" http://spring.io/guides[guides]
that use Spring Boot. If you need to solve a specific problem, check there first.
The http://spring.io[spring.io] web site contains many "`Getting Started`"
http://spring.io/guides[guides] that use Spring Boot. If you need to solve a specific
problem, check there first.
You can shortcut the steps below by going to https://start.spring.io and choosing the
"Web" starter from the dependencies searcher. Doing so generates a new
project structure so that you can <<getting-started-first-application-code,start coding
right away>>. Check the https://github.com/spring-io/initializr[Spring Initializr
documentation] for more details.
"Web" starter from the dependencies searcher. Doing so generates a new project structure
so that you can <<getting-started-first-application-code,start coding right away>>. Check
the https://github.com/spring-io/initializr[Spring Initializr documentation] for more
details.
====
Before we begin, open a terminal and run the following commands to ensure that you have
@ -477,8 +483,8 @@ that you have created a suitable folder and that it is your "`current directory`
[[getting-started-first-application-pom]]
=== Creating the POM
We need to start by creating a Maven `pom.xml` file. The `pom.xml` is the recipe that
is used to build your project. Open your favorite text editor and add the following:
We need to start by creating a Maven `pom.xml` file. The `pom.xml` is the recipe that is
used to build your project. Open your favorite text editor and add the following:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@ -526,29 +532,29 @@ endif::[]
</project>
----
The preceding listing should give you a working build. You can test it by running
`mvn package` (for now, you can ignore the "`jar will be empty - no content was marked for
The preceding listing should give you a working build. You can test it by running `mvn
package` (for now, you can ignore the "`jar will be empty - no content was marked for
inclusion!`" warning).
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs
include built-in support for Maven). For simplicity, we continue to use a plain
text editor for this example.
include built-in support for Maven). For simplicity, we continue to use a plain text
editor for this example.
[[getting-started-first-application-dependencies]]
=== Adding Classpath Dependencies
Spring Boot provides a number of "`Starters`" that let you add jars to your
classpath. Our sample application has already used `spring-boot-starter-parent` in the
`parent` section of the POM. The `spring-boot-starter-parent` is a special starter
that provides useful Maven defaults. It also provides a
Spring Boot provides a number of "`Starters`" that let you add jars to your classpath.
Our sample application has already used `spring-boot-starter-parent` in the `parent`
section of the POM. The `spring-boot-starter-parent` is a special starter that provides
useful Maven defaults. It also provides a
<<using-spring-boot.adoc#using-boot-dependency-management,`dependency-management`>>
section so that you can omit `version` tags for "`blessed`" dependencies.
Other "`Starters`" provide dependencies that you are likely to need when
developing a specific type of application. Since we are developing a web application, we
add a `spring-boot-starter-web` dependency. Before that, we can look at what we
currently have by running the following command:
Other "`Starters`" provide dependencies that you are likely to need when developing a
specific type of application. Since we are developing a web application, we add a
`spring-boot-starter-web` dependency. Before that, we can look at what we currently have
by running the following command:
[indent=0]
----
@ -558,8 +564,8 @@ currently have by running the following command:
----
The `mvn dependency:tree` command prints a tree representation of your project
dependencies. You can see that `spring-boot-starter-parent` provides no
dependencies by itself. To add the necessary dependencies, edit your `pom.xml` and add the
dependencies. You can see that `spring-boot-starter-parent` provides no dependencies by
itself. To add the necessary dependencies, edit your `pom.xml` and add the
`spring-boot-starter-web` dependency immediately below the `parent` section:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
@ -572,8 +578,8 @@ dependencies by itself. To add the necessary dependencies, edit your `pom.xml` a
</dependencies>
----
If you run `mvn dependency:tree` again, you see that there are now a number of
additional dependencies, including the Tomcat web server and Spring Boot itself.
If you run `mvn dependency:tree` again, you see that there are now a number of additional
dependencies, including the Tomcat web server and Spring Boot itself.
@ -617,10 +623,10 @@ _stereotype_ annotation. It provides hints for people reading the code and for S
that the class plays a specific role. In this case, our class is a web `@Controller`, so
Spring considers it when handling incoming web requests.
The `@RequestMapping` annotation provides "`routing`" information. It tells Spring
that any HTTP request with the `/` path should be mapped to the `home` method. The
`@RestController` annotation tells Spring to render the resulting string directly
back to the caller.
The `@RequestMapping` annotation provides "`routing`" information. It tells Spring that
any HTTP request with the `/` path should be mapped to the `home` method. The
`@RestController` annotation tells Spring to render the resulting string directly back to
the caller.
TIP: The `@RestController` and `@RequestMapping` annotations are Spring MVC annotations.
(They are not specific to Spring Boot.) See the {spring-reference}web.html#mvc[MVC
@ -631,15 +637,15 @@ section] in the Spring Reference Documentation for more details.
[[getting-started-first-application-auto-configuration]]
==== The @EnableAutoConfiguration Annotation
The second class-level annotation is `@EnableAutoConfiguration`. This annotation tells
Spring Boot to "`guess`" how you want to configure Spring, based on the jar
dependencies that you have added. Since `spring-boot-starter-web` added Tomcat and
Spring MVC, the auto-configuration assumes that you are developing a web application
and sets up Spring accordingly.
Spring Boot to "`guess`" how you want to configure Spring, based on the jar dependencies
that you have added. Since `spring-boot-starter-web` added Tomcat and Spring MVC, the
auto-configuration assumes that you are developing a web application and sets up Spring
accordingly.
.Starters and Auto-Configuration
****
Auto-configuration is designed to work well with "`Starters`", but the two concepts
are not directly tied. You are free to pick-and-choose jar dependencies outside of the
Auto-configuration is designed to work well with "`Starters`", but the two concepts are
not directly tied. You are free to pick and choose jar dependencies outside of the
starters and Spring Boot still does its best to auto-configure your application.
****
@ -648,12 +654,12 @@ starters and Spring Boot still does its best to auto-configure your application.
[[getting-started-first-application-main-method]]
==== The "`main`" Method
The final part of our application is the `main` method. This is just a standard method
that follows the Java convention for an application entry point. Our main method delegates
to Spring Boot's `SpringApplication` class by calling `run`. `SpringApplication`
bootstraps our application, starting Spring, which, in turn, starts the auto-configured
Tomcat web server. We need to pass `Example.class` as an argument to the `run` method to
tell `SpringApplication` which is the primary Spring component. The `args` array is also
passed through to expose any command-line arguments.
that follows the Java convention for an application entry point. Our main method
delegates to Spring Boot's `SpringApplication` class by calling `run`.
`SpringApplication` bootstraps our application, starting Spring, which, in turn, starts
the auto-configured Tomcat web server. We need to pass `Example.class` as an argument to
the `run` method to tell `SpringApplication` which is the primary Spring component. The
`args` array is also passed through to expose any command-line arguments.
@ -705,10 +711,10 @@ Java does not provide a standard way to load nested jar files (jar files that ar
themselves contained within a jar). This can be problematic if you are looking to
distribute a self-contained application.
To solve this problem, many developers use "`uber`" jars. An uber jar packages
all the classes from all the application's dependencies into a single archive. The problem
with this approach is that it becomes hard to see which libraries are in your application.
It can also be problematic if the same filename is used (but with different content) in
To solve this problem, many developers use "`uber`" jars. An uber jar packages all the
classes from all the application's dependencies into a single archive. The problem with
this approach is that it becomes hard to see which libraries are in your application. It
can also be problematic if the same filename is used (but with different content) in
multiple jars.
Spring Boot takes a <<appendix-executable-jar-format.adoc#executable-jar, different
@ -730,9 +736,9 @@ To create an executable jar, we need to add the `spring-boot-maven-plugin` to ou
</build>
----
NOTE: The `spring-boot-starter-parent` POM includes `<executions>` configuration to
bind the `repackage` goal. If you do not use the parent POM, you need to declare
this configuration yourself. See the {spring-boot-maven-plugin-site}/usage.html[plugin
NOTE: The `spring-boot-starter-parent` POM includes `<executions>` configuration to bind
the `repackage` goal. If you do not use the parent POM, you need to declare this
configuration yourself. See the {spring-boot-maven-plugin-site}/usage.html[plugin
documentation] for details.
Save your `pom.xml` and run `mvn package` from the command line, as follows:
@ -757,16 +763,16 @@ Save your `pom.xml` and run `mvn package` from the command line, as follows:
----
If you look in the `target` directory, you should see `myproject-0.0.1-SNAPSHOT.jar`. The
file should be around 10 MB in size. If you want to peek inside, you can use `jar tvf`, as
follows:
file should be around 10 MB in size. If you want to peek inside, you can use `jar tvf`,
as follows:
[indent=0]
----
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
----
You should also see a much smaller file named `myproject-0.0.1-SNAPSHOT.jar.original`
in the `target` directory. This is the original jar file that Maven created before it was
You should also see a much smaller file named `myproject-0.0.1-SNAPSHOT.jar.original` in
the `target` directory. This is the original jar file that Maven created before it was
repackaged by Spring Boot.
To run that application, use the `java -jar` command, as follows:
@ -794,17 +800,17 @@ As before, to exit the application, press `ctrl-c`.
[[getting-started-whats-next]]
== What to Read Next
Hopefully, this section provided some of the Spring Boot basics and got you
on your way to writing your own applications. If you are a task-oriented type of
developer, you might want to jump over to http://spring.io and check out some of the
http://spring.io/guides/[getting started] guides that solve specific
"`How do I do that with Spring?`" problems. We also have Spring Boot-specific
_<<howto.adoc#howto, How-to>>_ reference documentation.
Hopefully, this section provided some of the Spring Boot basics and got you on your way
to writing your own applications. If you are a task-oriented type of developer, you might
want to jump over to http://spring.io and check out some of the
http://spring.io/guides/[getting started] guides that solve specific "`How do I do that
with Spring?`" problems. We also have Spring Boot-specific
"`<<howto.adoc#howto, How-to>>`" reference documentation.
The http://github.com/{github-repo}[Spring Boot repository] also has a
{github-code}/spring-boot-samples[bunch of samples] you can run. The samples are
independent of the rest of the code (that is, you do not need to build the rest to run
or use the samples).
independent of the rest of the code (that is, you do not need to build the rest to run or
use the samples).
Otherwise, the next logical step is to read _<<using-spring-boot.adoc#using-boot>>_. If
you are really impatient, you could also jump ahead and read about

@ -57,10 +57,10 @@ Actuator endpoints let you monitor and interact with your application. Spring Bo
includes a number of built-in endpoints and lets you add your own. For example, the
`health` endpoint provides basic application health information.
The way that endpoints are exposed depends on the type of technology that you choose. Most
applications choose HTTP monitoring, where the ID of the endpoint along with a prefix of
`/application` is mapped to a URL. For example, by default, the `health` endpoint is
mapped to `/application/health`.
The way that endpoints are exposed depends on the type of technology that you choose.
Most applications choose HTTP monitoring, where the ID of the endpoint along with a
prefix of `/application` is mapped to a URL. For example, by default, the `health`
endpoint is mapped to `/application/health`.
The following technology-agnostic endpoints are available:
@ -171,8 +171,8 @@ user authentication. When '`Spring Security`' is added, by default, '`basic`'
authentication is used. The username is`user` and the password is a random generated
password (which is printed on the console when the application starts).
TIP: Generated passwords are logged as the application starts. To find the password in the
console, search for '`Using default security password`'.
TIP: Generated passwords are logged as the application starts. To find the password in
the console, search for '`Using default security password`'.
You can use Spring properties to change the username and password and to change the
security role(s) required to access the endpoints. For example, you might set the
@ -187,8 +187,8 @@ following properties in your `application.properties`:
If your application has custom security configuration and you want all your actuator
endpoints to be accessible without authentication, you need to explicitly configure that
in your security configuration. Also, you need to change the `management.security.enabled`
property to `false`.
in your security configuration. Also, you need to change the
`management.security.enabled` property to `false`.
If your custom security configuration secures your actuator endpoints, you also need to
ensure that the authenticated user has the roles specified under
@ -203,11 +203,11 @@ additional role check.
[[production-ready-customizing-endpoints]]
=== Customizing Endpoints
Endpoints can be customized by using Spring properties. You can change whether an endpoint
is `enabled` and its `id`.
Endpoints can be customized by using Spring properties. You can change whether an
endpoint is `enabled` and its `id`.
For example, the following `application.properties` changes the id of the `beans` endpoint
and also enables `shutdown`:
For example, the following `application.properties` changes the id of the `beans`
endpoint and also enables `shutdown`:
[source,properties,indent=0]
----
@ -218,9 +218,9 @@ and also enables `shutdown`:
NOTE: The prefix ‟`endpoints` + `.` + `name`” is used to uniquely identify the endpoint
that is being configured.
By default, all endpoints except for `shutdown` are enabled. If you prefer to specifically
"`opt-in`" endpoint enablement, you can use the `endpoints.default.enabled` property. For
example, the following settings disables _all_ endpoints except for `info`:
By default, all endpoints except for `shutdown` are enabled. If you prefer to
specifically "`opt-in`" endpoint enablement, you can use the `endpoints.default.enabled`
property. For example, the following settings disables _all_ endpoints except for `info`:
[source,properties,indent=0]
----
@ -272,29 +272,29 @@ application, over HTTP as well.
TIP: If you do this as a library feature, consider adding a configuration class annotated
with `@ManagementContextConfiguration` to `/META-INF/spring.factories` under the key,
`org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration`. If you do
so and if your users ask for a separate management port or address, the endpoint moves to
a child context with all the other web endpoints.
`org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration`. If you
do so and if your users ask for a separate management port or address, the endpoint moves
to a child context with all the other web endpoints.
[[production-ready-health]]
=== Health Information
You can use health information to check the status of your running application. It is
often used by monitoring software to alert someone when a production system goes down. The
default information exposed by the `health` endpoint depends on how it is accessed. For an
unauthenticated connection in a secure application, a simple '`status`' message is
often used by monitoring software to alert someone when a production system goes down.
The default information exposed by the `health` endpoint depends on how it is accessed.
For an unauthenticated connection in a secure application, a simple '`status`' message is
returned. For an authenticated connection, additional details are also displayed. (See
<<production-ready-health-access-restrictions>> for HTTP details.)
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.
{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.
@ -373,12 +373,13 @@ NOTE: The identifier for a given `HealthIndicator` is the name of the bean witho
`HealthIndicator` suffix, if it exists. In the preceding example, the health information
is available in an entry named `my`.
In addition to Spring Boot's predefined {sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`]
types, it is also possible for `Health` to return a custom `Status` that represents a new
system state. In such cases, a custom implementation of the
In addition to Spring Boot's predefined
{sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`] types, it is also possible for
`Health` to return a custom `Status` that represents a new system state. In such cases, a
custom implementation of the
{sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`] interface
also needs to be provided, or the default implementation has to be configured by using the
`management.health.status.order` configuration property.
also needs to be provided, or the default implementation has to be configured by using
the `management.health.status.order` configuration property.
For example, assume a new `Status` with code `FATAL` is being used in one of your
`HealthIndicator` implementations. To configure the severity order, add the following
@ -389,8 +390,8 @@ to your application properties:
management.health.status.order=FATAL, DOWN, OUT_OF_SERVICE, UNKNOWN, UP
----
The HTTP status code in the response reflects the overall health status (for example, `UP`
maps to 200, while `OUT_OF_SERVICE` and `DOWN` map to 503). You might also want to
The HTTP status code in the response reflects the overall health status (for example,
`UP` maps to 200, while `OUT_OF_SERVICE` and `DOWN` map to 503). You might also want to
register custom status mappings if you access the health endpoint over HTTP. For example,
the following property maps `FATAL` to 503 (service unavailable):
@ -454,8 +455,8 @@ property.
[[production-ready-application-info-env]]
==== Custom Application Information
You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring
properties. All `Environment` properties under the info key are automatically exposed. For
example, you could add the following settings to your `application.properties` file:
properties. All `Environment` properties under the info key are automatically exposed.
For example, you could add the following settings to your `application.properties` file:
[source,properties,indent=0]
----
@ -485,8 +486,8 @@ Assuming you use Maven, you could rewrite the preceding example as follows:
==== Git Commit Information
Another useful feature of the `info` endpoint is its ability to publish information about
the state of your `git` source code repository when the project was built. If a
`GitProperties` bean is available, the `git.branch`, `git.commit.id` and `git.commit.time`
properties are exposed.
`GitProperties` bean is available, the `git.branch`, `git.commit.id` and
`git.commit.time` properties are exposed.
TIP: A `GitProperties` bean is auto-configured if a `git.properties` file is available at
the root of the classpath. See
@ -504,9 +505,9 @@ If you want to display the full git information (that is, the full content of
[[production-ready-application-info-build]]
==== Build Information
If a `BuildProperties` bean is available, the `info` endpoint can also publish information
about your build. This happens if a `META-INF/build-info.properties` file is available in
the classpath.
If a `BuildProperties` bean is available, the `info` endpoint can also publish
information about your build. This happens if a `META-INF/build-info.properties` file is
available in the classpath.
TIP: The Maven and Gradle plugins can both generate that file. See
"<<howto.adoc#howto-build-info,Generate build information>>" for more details.
@ -564,10 +565,10 @@ exposed as `/application/health`.
[[production-ready-customizing-management-server-context-path]]
=== Customizing the Management Endpoint Paths
Sometimes, it is useful to customize the prefix for the management endpoints. For example,
your application might already use `/application` for another purpose. You can use the
`management.endpoints.web.base-path` property to change the prefix for your management
endpoint, as shown in the following example:
Sometimes, it is useful to customize the prefix for the management endpoints. For
example, your application might already use `/application` for another purpose. You can
use the `management.endpoints.web.base-path` property to change the prefix for your
management endpoint, as shown in the following example:
[source,properties,indent=0]
----
@ -591,18 +592,18 @@ Exposing management endpoints by using the default HTTP port is a sensible choic
cloud based deployments. If, however, your application runs inside your own data center,
you may prefer to expose endpoints by using a different HTTP port.
You can set the `management.server.port` property to change the HTTP port, as shown in the
following example:
You can set the `management.server.port` property to change the HTTP port, as shown in
the following example:
[source,properties,indent=0]
----
management.server.port=8081
----
Since your management port is often protected by a firewall and not exposed to the public,
you might not need security on the management endpoints, even if your main application is
secure. In that case, you should have Spring Security on the classpath, and you can
disable management security as follows:
Since your management port is often protected by a firewall and not exposed to the
public, you might not need security on the management endpoints, even if your main
application is secure. In that case, you should have Spring Security on the classpath,
and you can disable management security as follows:
[source,properties,indent=0]
----
@ -682,10 +683,10 @@ If you do not want to expose endpoints over HTTP, you can set the management por
[[production-ready-health-access-restrictions]]
=== HTTP Health Endpoint Format and Access Restrictions
The information exposed by the health endpoint varies, depending on whether it is accessed
anonymously and whether the enclosing application is secure. By default, when accessed
anonymously in a secure application, any details about the server's health are hidden and
the endpoint indicates whether the server is up or down.
The information exposed by the health endpoint varies, depending on whether it is
accessed anonymously and whether the enclosing application is secure. By default, when
accessed anonymously in a secure application, any details about the server's health are
hidden and the endpoint indicates whether the server is up or down.
The following example shows a summarized HTTP response (default for anonymous request):
@ -745,8 +746,8 @@ The following example shows a detailed HTTP response:
[[production-ready-jmx]]
== Monitoring and Management over JMX
Java Management Extensions (JMX) provide a standard mechanism to monitor and manage
applications. By default, Spring Boot exposes management endpoints as JMX MBeans under the
`org.springframework.boot` domain.
applications. By default, Spring Boot exposes management endpoints as JMX MBeans under
the `org.springframework.boot` domain.
@ -831,9 +832,9 @@ If you use Jolokia but do not want Spring Boot to configure it, set the
== Loggers
Spring Boot Actuator includes the ability to view and configure the log levels of your
application at runtime. You can view either the entire list or an individual logger's
configuration, which is made up of both the explicitly configured logging level as well as
the effective logging level given to it by the logging framework. These levels can be one
of:
configuration, which is made up of both the explicitly configured logging level as well
as the effective logging level given to it by the logging framework. These levels can be
one of:
* `TRACE`
* `DEBUG`
@ -879,9 +880,9 @@ monitoring systems:
- https://prometheus.io[Prometheus]
Micrometer provides a separate module for each supported monitoring system. Depending on
one (or more) of these modules is sufficient to get started with Micrometer in your Spring
Boot application. To learn more about Micrometer's capabilities, please refer to its
https://micrometer.io/docs[reference documentation].
one (or more) of these modules is sufficient to get started with Micrometer in your
Spring Boot application. To learn more about Micrometer's capabilities, please refer to
its https://micrometer.io/docs[reference documentation].
@ -889,8 +890,8 @@ https://micrometer.io/docs[reference documentation].
=== Spring MVC Metrics
Auto-configuration enables the instrumentation of requests handled by Spring MVC. When
`spring.metrics.web.server.auto-time-requests` is `true`, this instrumentation occurs for
all requests. Alternatively, when set to `false`, you can enable instrumentation by adding
`@Timed` to a request-handling method.
all requests. Alternatively, when set to `false`, you can enable instrumentation by
adding `@Timed` to a request-handling method.
By default, metrics are generated with the name, `http.server.requests`. The name can be
customized by setting the `spring.metrics.web.server.requests-metrics-name` property.
@ -970,10 +971,10 @@ following information:
[[production-ready-metrics-jdbc]]
=== DataSource metrics
Auto-configuration will enable the instrumentation of all available `DataSources` with a
metric named `data.source`. Data source instrumentation results in gauges representing the
currently active, maximum allowed, and minimum allowed connections in the pool. Each of
these gauges has a name which is prefixed by `data.source` by default. The prefix can be
be customized using the `spring.metrics.jdbc.datasource-metric-name` property.
metric named `data.source`. Data source instrumentation results in gauges representing
the currently active, maximum allowed, and minimum allowed connections in the pool. Each
of these gauges has a name which is prefixed by `data.source` by default. The prefix can
be customized by using the `spring.metrics.jdbc.datasource-metric-name` property.
Metrics will also be tagged by the name of the `DataSource` computed based on the bean
name.
@ -1126,8 +1127,8 @@ and logged.
By default, an `InMemoryTraceRepository` that stores the last 100 events is used. If you
need to expand the capacity, you can define your own instance of the
`InMemoryTraceRepository` bean. You can also create your own alternative `TraceRepository`
implementation.
`InMemoryTraceRepository` bean. You can also create your own alternative
`TraceRepository` implementation.
@ -1136,11 +1137,11 @@ implementation.
In the `spring-boot` module, you can find two classes to create files that are often
useful for process monitoring:
* `ApplicationPidFileWriter` creates a file containing the application PID (by default, in
the application directory with the file name, `application.pid`).
* `ApplicationPidFileWriter` creates a file containing the application PID (by default,
in the application directory with the file name, `application.pid`).
* `EmbeddedServerPortFileWriter` creates a file (or files) containing the ports of the
embedded server (by default, in the application directory with the file name
`application.port`).
embedded server (by default, in the application directory with the file name
`application.port`).
By default, these writers are not activated, but you can enable them in one of the ways
described in the next section.

@ -4,9 +4,9 @@
[partintro]
--
This section goes into more detail about how you should use Spring Boot. It covers topics
such as build systems, auto-configuration, and how to run your applications. We also cover
some Spring Boot best practices. Although there is nothing particularly special about
Spring Boot (it is just another library that you can consume), there are a few
such as build systems, auto-configuration, and how to run your applications. We also
cover some Spring Boot best practices. Although there is nothing particularly special
about Spring Boot (it is just another library that you can consume), there are a few
recommendations that, when followed, make your development process a little easier.
If you are starting out with Spring Boot, you should probably read the
@ -21,23 +21,23 @@ section.
It is strongly recommended that you choose a build system that supports
<<using-boot-dependency-management,_dependency management_>> and that can consume
artifacts published to the "`Maven Central`" repository. We would recommend that you
choose Maven or Gradle. It is possible to get Spring Boot to work with other build systems
(Ant, for example), but they are not particularly well supported.
choose Maven or Gradle. It is possible to get Spring Boot to work with other build
systems (Ant, for example), but they are not particularly well supported.
[[using-boot-dependency-management]]
=== Dependency Management
Each release of Spring Boot provides a curated list of dependencies that it supports. In
practice, you do not need to provide a version for any of these dependencies in your build
configuration, as Spring Boot is managing that for you. When you upgrade Spring Boot
itself, these dependencies are upgraded as well in a consistent way.
practice, you do not need to provide a version for any of these dependencies in your
build configuration, as Spring Boot is managing that for you. When you upgrade Spring
Boot itself, these dependencies are upgraded as well in a consistent way.
NOTE: You can still specify a version and override Spring Boot's recommendations if you
need to do so.
The curated list contains all the spring modules that you can use with Spring Boot as well
as a refined list of third party libraries. The list is available as a standard
The curated list contains all the spring modules that you can use with Spring Boot as
well as a refined list of third party libraries. The list is available as a standard
<<using-boot-maven-without-a-parent,Bills of Materials (`spring-boot-dependencies`)>>
that can be used with both <<using-boot-maven-parent-pom,Maven>> and
<<using-boot-gradle,Gradle>>.
@ -55,17 +55,18 @@ defaults. The parent project provides the following features:
* Java 1.8 as the default compiler level.
* UTF-8 source encoding.
* A <<using-boot-dependency-management,Dependency Management section>>, inherited from
the spring-boot-dependencies pom, that manages the versions of common dependencies. This
dependency management lets you omit <version> tags for those dependencies when used in
your own pom.
* Sensible https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html[resource
filtering].
the spring-boot-dependencies pom, that manages the versions of common dependencies. This
dependency management lets you omit <version> tags for those dependencies when used in
your own pom.
* Sensible
https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html[resource
filtering].
* Sensible plugin configuration (http://www.mojohaus.org/exec-maven-plugin/[exec plugin],
https://github.com/ktoso/maven-git-commit-id-plugin[Git commit ID], and
http://maven.apache.org/plugins/maven-shade-plugin/[shade]).
* Sensible resource filtering for `application.properties` and `application.yml` including
profile-specific files (for example, `application-foo.properties` and
`application-foo.yml`)
https://github.com/ktoso/maven-git-commit-id-plugin[Git commit ID], and
http://maven.apache.org/plugins/maven-shade-plugin/[shade]).
* Sensible resource filtering for `application.properties` and `application.yml`
including profile-specific files (for example, `application-foo.properties` and
`application-foo.yml`)
Note that, since the `application.properties` and `application.yml` files accept Spring
style placeholders (`${...}`), the Maven filtering is changed to use `@..@` placeholders.
@ -75,8 +76,8 @@ style placeholders (`${...}`), the Maven filtering is changed to use `@..@` plac
[[using-boot-maven-parent-pom]]
==== Inheriting the Starter Parent
To configure your project to inherit from the `spring-boot-starter-parent` set
the `parent`, as follows:
To configure your project to inherit from the `spring-boot-starter-parent` set the
`parent`, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@ -102,20 +103,21 @@ would add the following to your `pom.xml`:
</properties>
----
TIP: Check the {github-code}/spring-boot-project/spring-boot-dependencies/pom.xml[`spring-boot-dependencies` pom]
TIP: Check the
{github-code}/spring-boot-project/spring-boot-dependencies/pom.xml[`spring-boot-dependencies` pom]
for a list of supported properties.
[[using-boot-maven-without-a-parent]]
==== Using Spring Boot without the Parent POM
Not everyone likes inheriting from the `spring-boot-starter-parent` POM. You may have your
own corporate standard parent that you need to use or you may prefer to explicitly
Not everyone likes inheriting from the `spring-boot-starter-parent` POM. You may have
your own corporate standard parent that you need to use or you may prefer to explicitly
declare all your Maven configuration.
If you do not want to use the `spring-boot-starter-parent`, you can still keep the benefit
of the dependency management (but not the plugin management) by using a `scope=import`
dependency, as follows:
If you do not want to use the `spring-boot-starter-parent`, you can still keep the
benefit of the dependency management (but not the plugin management) by using a
`scope=import` dependency, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@ -136,8 +138,8 @@ dependency, as follows:
The preceding sample setup does not let you override individual dependencies by using a
property, as explained above. To achieve the same result, you need to add an entry in the
`dependencyManagement` of your project **before** the `spring-boot-dependencies` entry.
For instance, to upgrade to another Spring Data release train, you could add the following
element to your `pom.xml`:
For instance, to upgrade to another Spring Data release train, you could add the
following element to your `pom.xml`:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@ -197,7 +199,7 @@ To learn about using Spring Boot with Gradle, please refer to the documentation
Spring Boot's Gradle plugin:
* Reference ({spring-boot-gradle-plugin}/reference/html[HTML] and
{spring-boot-gradle-plugin}/reference/pdf/spring-boot-gradle-plugin-reference.pdf[PDF])
{spring-boot-gradle-plugin}/reference/pdf/spring-boot-gradle-plugin-reference.pdf[PDF])
* {spring-boot-gradle-plugin}/api[API]
[[using-boot-ant]]
@ -288,9 +290,9 @@ search dependencies by name. For example, with the appropriate Eclipse or STS pl
installed, you can simply hit `ctrl-space` in the POM editor and type
"`spring-boot-starter`" for a complete list.
As explained in the <<spring-boot-features#boot-features-custom-starter,Creating Your Own
Starter>> section, third party starters should not start with `spring-boot`, as it is
reserved for official Spring Boot artifacts. Rather, a third-party starter typically
As explained in the "`<<spring-boot-features#boot-features-custom-starter,Creating Your
Own Starter>>`" section, third party starters should not start with `spring-boot`, as it
is reserved for official Spring Boot artifacts. Rather, a third-party starter typically
starts with the name of the project. For example, a third-party starter project called
`thirdpartyproject` would typically be named `thirdpartyproject-spring-boot-starter`.
****
@ -308,8 +310,7 @@ _<<production-ready-features.adoc#production-ready, production ready>>_ features
include::../../../target/generated-resources/production-starters.adoc[]
Finally, Spring Boot also includes the following starters that can be used if you want to
exclude
or swap specific technical facets:
exclude or swap specific technical facets:
.Spring Boot technical starters
include::../../../target/generated-resources/technical-starters.adoc[]
@ -331,9 +332,9 @@ best practices that help.
=== Using the "`default`" Package
When a class does not include a `package` declaration, it is considered to be in the
"`default package`". The use of the "`default package`" is generally discouraged and
should be avoided. It can cause particular problems for Spring Boot applications that
use the `@ComponentScan`, `@EntityScan`, or `@SpringBootApplication` annotations, since
every class from every jar is read.
should be avoided. It can cause particular problems for Spring Boot applications that use
the `@ComponentScan`, `@EntityScan`, or `@SpringBootApplication` annotations, since every
class from every jar is read.
TIP: We recommend that you follow Java's recommended package naming conventions and use a
reversed domain name (for example, `com.example.project`).
@ -403,9 +404,9 @@ The `Application.java` file would declare the `main` method, along with the basi
[[using-boot-configuration-classes]]
== Configuration Classes
Spring Boot favors Java-based configuration. Although it is possible to use
`SpringApplication` with XML sources, we generally recommend that your primary source be a
single `@Configuration` class. Usually the class that defines the `main` method is a good
candidate as the primary `@Configuration`.
`SpringApplication` with XML sources, we generally recommend that your primary source be
a single `@Configuration` class. Usually the class that defines the `main` method is a
good candidate as the primary `@Configuration`.
TIP: Many Spring configuration examples have been published on the Internet that use XML
configuration. If possible, always try to use the equivalent Java-based configuration.
@ -433,9 +434,9 @@ XML configuration files.
[[using-boot-auto-configuration]]
== Auto-configuration
Spring Boot auto-configuration attempts to automatically configure your Spring
application based on the jar dependencies that you have added. For example, if
`HSQLDB` is on your classpath, and you have not manually configured any database
connection beans, then Spring Boot auto-configures an in-memory database.
application based on the jar dependencies that you have added. For example, if `HSQLDB`
is on your classpath, and you have not manually configured any database connection beans,
then Spring Boot auto-configures an in-memory database.
You need to opt-in to auto-configuration by adding the `@EnableAutoConfiguration` or
`@SpringBootApplication` annotations to one of your `@Configuration` classes.
@ -447,13 +448,13 @@ recommend that you add it to your primary `@Configuration` class.
[[using-boot-replacing-auto-configuration]]
=== Gradually Replacing Auto-configuration
Auto-configuration is noninvasive. At any point, you can start to define your own
configuration to replace specific parts of the auto-configuration. For example, if you add
your own `DataSource` bean, the default embedded database support backs away.
Auto-configuration is non-invasive. At any point, you can start to define your own
configuration to replace specific parts of the auto-configuration. For example, if you
add your own `DataSource` bean, the default embedded database support backs away.
If you need to find out what auto-configuration is currently being applied, and why, start
your application with the `--debug` switch. Doing so enables debug logs for a selection of
core loggers and logs an auto-configuration report to the console.
If you need to find out what auto-configuration is currently being applied, and why,
start your application with the `--debug` switch. Doing so enables debug logs for a
selection of core loggers and logs an auto-configuration report to the console.
@ -476,17 +477,18 @@ as shown in the following example:
----
If the class is not on the classpath, you can use the `excludeName` attribute of the
annotation and specify the fully qualified name instead. Finally, you can also control the
list of auto-configuration classes to exclude by using the `spring.autoconfigure.exclude`
property.
annotation and specify the fully qualified name instead. Finally, you can also control
the list of auto-configuration classes to exclude by using the
`spring.autoconfigure.exclude` property.
TIP: You can define exclusions both at the annotation level and by using the property.
[[using-boot-spring-beans-and-dependency-injection]]
== Spring Beans and Dependency Injection
You are free to use any of the standard Spring Framework techniques to define your beans
and their injected dependencies. For simplicity, we often find that using `@ComponentScan`
(to find your beans) and using `@Autowired` (to do constructor injection) works well.
and their injected dependencies. For simplicity, we often find that using
`@ComponentScan` (to find your beans) and using `@Autowired` (to do constructor
injection) works well.
If you structure your code as suggested above (locating your application class in a root
package), you can add `@ComponentScan` without any arguments. All of your application
@ -545,10 +547,10 @@ TIP: Notice how using constructor injection lets the `riskAssessor` field be mar
[[using-boot-using-springbootapplication-annotation]]
== Using the @SpringBootApplication Annotation
Many Spring Boot developers always have their main class annotated with `@Configuration`,
`@EnableAutoConfiguration`, and `@ComponentScan`. Since these annotations are so frequently
used together (especially if you follow the <<using-boot-structuring-your-code, best
practices>> above), Spring Boot provides a convenient `@SpringBootApplication`
alternative.
`@EnableAutoConfiguration`, and `@ComponentScan`. Since these annotations are so
frequently used together (especially if you follow the
<<using-boot-structuring-your-code, best practices>> above), Spring Boot provides a
convenient `@SpringBootApplication` alternative.
The `@SpringBootApplication` annotation is equivalent to using `@Configuration`,
`@EnableAutoConfiguration`, and `@ComponentScan` with their default attributes, as shown
@ -579,9 +581,10 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes
[[using-boot-running-your-application]]
== Running Your Application
One of the biggest advantages of packaging your application as a jar and using an embedded
HTTP server is that you can run your application as you would any other. Debugging Spring
Boot applications is also easy. You do not need any special IDE plugins or extensions.
One of the biggest advantages of packaging your application as a jar and using an
embedded HTTP server is that you can run your application as you would any other.
Debugging Spring Boot applications is also easy. You do not need any special IDE plugins
or extensions.
NOTE: This section only covers jar based packaging. If you choose to package your
application as a war file, you should refer to your server and IDE documentation.
@ -590,10 +593,10 @@ application as a war file, you should refer to your server and IDE documentation
[[using-boot-running-from-an-ide]]
=== Running from an IDE
You can run a Spring Boot application from your IDE as a simple Java application. However,
you first need to import your project. Import steps vary depending on your IDE and build
system. Most IDEs can import Maven projects directly. For example, Eclipse users can
select `Import...` -> `Existing Maven Projects` from the `File` menu.
You can run a Spring Boot application from your IDE as a simple Java application.
However, you first need to import your project. Import steps vary depending on your IDE
and build system. Most IDEs can import Maven projects directly. For example, Eclipse
users can select `Import...` -> `Existing Maven Projects` from the `File` menu.
If you cannot directly import your project into your IDE, you may be able to generate IDE
metadata by using a build plugin. Maven includes plugins for
@ -602,8 +605,8 @@ http://maven.apache.org/plugins/maven-idea-plugin/[IDEA]. Gradle offers plugins
{gradle-user-guide}/userguide.html[various IDEs].
TIP: If you accidentally run a web application twice, you see a "`Port already in use`"
error. STS users can use the `Relaunch` button rather than the `Run` button to ensure that
any existing instance is closed.
error. STS users can use the `Relaunch` button rather than the `Run` button to ensure
that any existing instance is closed.
@ -652,16 +655,16 @@ shown in the following example:
[[using-boot-running-with-the-gradle-plugin]]
=== Using the Gradle Plugin
The Spring Boot Gradle plugin also includes a `bootRun` task that can be used to run your
application in an exploded form. The `bootRun` task is added whenever you apply
the `org.springframework.boot` and `java` plugins and is shown in the following example:
application in an exploded form. The `bootRun` task is added whenever you apply the
`org.springframework.boot` and `java` plugins and is shown in the following example:
[indent=0,subs="attributes"]
----
$ gradle bootRun
----
You might also want to use the `JAVA_OPTS` operating system environment variable, as shown
in the following example:
You might also want to use the `JAVA_OPTS` operating system environment variable, as
shown in the following example:
[indent=0,subs="attributes"]
----
@ -752,9 +755,9 @@ TIP: For a complete list of the properties that are applied by the devtools, see
=== Automatic Restart
Applications that use `spring-boot-devtools` automatically restart whenever files on the
classpath change. This can be a useful feature when working in an IDE, as it gives a very
fast feedback loop for code changes. By default, any entry on the classpath that points to
a folder is monitored for changes. Note that certain resources, such as static assets and
view templates, <<using-boot-devtools-restart-exclude, do not need to restart the
fast feedback loop for code changes. By default, any entry on the classpath that points
to a folder is monitored for changes. Note that certain resources, such as static assets
and view templates, <<using-boot-devtools-restart-exclude, do not need to restart the
application>>.
.Triggering a restart
@ -762,16 +765,16 @@ application>>.
As DevTools monitors classpath resources, the only way to trigger a restart is to update
the classpath. The way in which you cause the classpath to be updated depends on the IDE
that you are using. In Eclipse, saving a modified file causes the classpath to be updated
and triggers a restart. In IntelliJ IDEA, building the project (`Build +->+ Make Project`)
will have the same effect.
and triggers a restart. In IntelliJ IDEA, building the project
(`Build +->+ Make Project`) has the same effect.
****
[NOTE]
====
As long as forking is enabled, you can also start your application by using the supported
build plugins (Maven and Gradle), since DevTools needs an isolated application classloader
to operate properly. By default, Gradle and Maven do that when they detect DevTools on the
classpath.
build plugins (Maven and Gradle), since DevTools needs an isolated application
classloader to operate properly. By default, Gradle and Maven do that when they detect
DevTools on the classpath.
====
@ -784,9 +787,10 @@ NOTE: DevTools relies on the application context's shutdown hook to close it dur
restart. It does not work correctly if you have disabled the shutdown hook
(`SpringApplication.setRegisterShutdownHook(false)`).
NOTE: When deciding if an entry on the classpath should trigger a restart when it changes,
DevTools automatically ignores projects named `spring-boot`, `spring-boot-devtools`,
`spring-boot-autoconfigure`, `spring-boot-actuator`, and `spring-boot-starter`.
NOTE: When deciding if an entry on the classpath should trigger a restart when it
changes, DevTools automatically ignores projects named `spring-boot`,
`spring-boot-devtools`, `spring-boot-autoconfigure`, `spring-boot-actuator`, and
`spring-boot-starter`.
NOTE: DevTools needs to customize the `ResourceLoader` used by the `ApplicationContext`.
If your application provides one already, it is going to be wrapped. Direct override of
@ -799,8 +803,8 @@ The restart technology provided by Spring Boot works by using two classloaders.
that do not change (for example, those from third-party jars) are loaded into a _base_
classloader. Classes that you are actively developing are loaded into a _restart_
classloader. When the application is restarted, the _restart_ classloader is thrown away
and a new one is created. This approach means that application restarts are typically much
faster than "`cold starts`", since the _base_ classloader is already available and
and a new one is created. This approach means that application restarts are typically
much faster than "`cold starts`", since the _base_ classloader is already available and
populated.
If you find that restarts are not quick enough for your applications or you encounter
@ -817,9 +821,9 @@ Certain resources do not necessarily need to trigger a restart when they are cha
example, Thymeleaf templates can be edited in-place. By default, changing resources
in `/META-INF/maven`, `/META-INF/resources`, `/resources`, `/static`, `/public`, or
`/templates` does not trigger a restart but does trigger a
<<using-boot-devtools-livereload, live reload>>. If you want to customize these exclusions,
you can use the `spring.devtools.restart.exclude` property. For example, to exclude only
`/static` and `/public` you would set the following property:
<<using-boot-devtools-livereload, live reload>>. If you want to customize these
exclusions, you can use the `spring.devtools.restart.exclude` property. For example, to
exclude only `/static` and `/public` you would set the following property:
[indent=0]
----
@ -834,8 +838,8 @@ TIP: If you want to keep those defaults and _add_ additional exclusions, use the
==== Watching Additional Paths
You may want your application to be restarted or reloaded when you make changes to files
that are not on the classpath. To do so, use the
`spring.devtools.restart.additional-paths` property to configure additional paths to watch
for changes. You can use the `spring.devtools.restart.exclude` property
`spring.devtools.restart.additional-paths` property to configure additional paths to
watch for changes. You can use the `spring.devtools.restart.exclude` property
<<using-boot-devtools-restart-exclude, described above>> to control whether changes
beneath the additional paths trigger a full restart or a
<<using-boot-devtools-livereload, live reload>>.
@ -845,14 +849,14 @@ beneath the additional paths trigger a full restart or a
[[using-boot-devtools-restart-disable]]
==== Disabling Restart
If you do not want to use the restart feature, you can disable it by using the
`spring.devtools.restart.enabled` property. In most cases, you can set this property in your
`application.properties` (doing so still initializes the restart classloader, but it does not
watch for file changes).
`spring.devtools.restart.enabled` property. In most cases, you can set this property in
your `application.properties` (doing so still initializes the restart classloader, but it
does not watch for file changes).
If you need to _completely_ disable restart support (for example, because it doesn't work
with a specific library), you need to set the `spring.devtools.restart.enabled` `System`
property to `false` before calling `SpringApplication.run(...)`, as shown in the following
example:
property to `false` before calling `SpringApplication.run(...)`, as shown in the
following example:
[source,java,indent=0]
----
@ -868,13 +872,13 @@ example:
==== Using a Trigger File
If you work with an IDE that continuously compiles changed files, you might prefer to
trigger restarts only at specific times. To do so, you can use a "`trigger file`", which
is a special file that must be modified when you want to actually trigger a restart check.
Changing the file only triggers the check and the restart will only occur if Devtools has
detected it has to do something. The trigger file can be updated manually or via an IDE
plugin.
is a special file that must be modified when you want to actually trigger a restart
check. Changing the file only triggers the check and the restart will only occur if
Devtools has detected it has to do something. The trigger file can be updated manually or
with an IDE plugin.
To use a trigger file, set the `spring.devtools.restart.trigger-file` property to the path
of your trigger file.
To use a trigger file, set the `spring.devtools.restart.trigger-file` property to the
path of your trigger file.
TIP: You might want to set `spring.devtools.restart.trigger-file` as a
<<using-boot-devtools-globalsettings,global setting>>, so that all your projects behave
@ -929,8 +933,8 @@ authors.
[[using-boot-devtools-livereload]]
=== LiveReload
The `spring-boot-devtools` module includes an embedded LiveReload server that can be used
to trigger a browser refresh when a resource is changed. LiveReload browser extensions are
freely available for Chrome, Firefox and Safari from
to trigger a browser refresh when a resource is changed. LiveReload browser extensions
are freely available for Chrome, Firefox and Safari from
http://livereload.com/extensions/[livereload.com].
If you do not want to start the LiveReload server when your application runs, you can set
@ -963,8 +967,8 @@ property:
=== Remote Applications
The Spring Boot developer tools are not just limited to local development. You can also
use several features when running applications remotely. Remote support is opt-in. To
enable it, you need to make sure that `devtools` is included in the repackaged archive, as
shown in the following listing:
enable it, you need to make sure that `devtools` is included in the repackaged archive,
as shown in the following listing:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@ -981,8 +985,8 @@ shown in the following listing:
</build>
----
Then you need to set a `spring.devtools.remote.secret` property, as shown in the following
example:
Then you need to set a `spring.devtools.remote.secret` property, as shown in the
following example:
[source,properties,indent=0]
----
@ -994,8 +998,8 @@ should never enable support on a production deployment.
Remote devtools support is provided in two parts: a server-side endpoint that accepts
connections and a client application that you run in your IDE. The server component is
automatically enabled when the `spring.devtools.remote.secret` property is set. The client
component must be launched manually.
automatically enabled when the `spring.devtools.remote.secret` property is set. The
client component must be launched manually.
@ -1013,7 +1017,7 @@ you have deployed to Cloud Foundry, you would do the following:
* Browse for the `my-app` project.
* Use `org.springframework.boot.devtools.RemoteSpringApplication` as the main class.
* Add `+++https://myapp.cfapps.io+++` to the `Program arguments` (or whatever your remote
URL is).
URL is).
A running remote client might resemble the following listing:
@ -1074,6 +1078,6 @@ _<<production-ready-features.adoc#production-ready>>_ for details.
== What to Read Next
You should now understand how you can use Spring Boot and some best practices that you
should follow. You can now go on to learn about specific
_<<spring-boot-features#boot-features, Spring Boot features>>_ in depth, or you could skip
ahead and read about the "`<<production-ready-features#production-ready, production
_<<spring-boot-features#boot-features, Spring Boot features>>_ in depth, or you could
skip ahead and read about the "`<<production-ready-features#production-ready, production
ready>>`" aspects of Spring Boot.

Loading…
Cancel
Save