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