不能登录网站,提示Please check the box in the security check面膜form before attempting to log in again.

please check the security box to continue什么意思_百度知道
please check the security box to continue什么意思
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
请先检查保险箱再继续
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Access denied | www.arecontvision.com used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website (www.arecontvision.com) has banned your access based on your browser's signature (4400b61dbbca53d8-ua98).Spring Boot Reference GuideSpring Boot Reference GuideAuthorsPhillip Webb, Dave Syer, Josh Long, St&phane Nicoll, Rob Winch, Andy Wilkinson, Marcel Overdijk, Christian Dupuis, S&bastien Deleuze, Michael Simons, Vedran Pavić, Jay Bryant, Madhura Bhave
Copies of this document may be made for your own use and for distribution to
others, provided that you do not charge any fee for such copies and further
provided that each copy contains this Copyright Notice, whether distributed in
print or electronically.
Table of ContentsPart&I.&Spring Boot DocumentationThis section provides a brief overview of Spring Boot reference documentation. It serves
as a map for the rest of the document.1.&About the DocumentationThe Spring Boot reference guide is available asThe latest copy
is available at .Copies of this document may be made for your own use and for distribution to others,
provided that you do not charge any fee for such copies and further provided that each
copy contains this Copyright Notice, whether distributed in print or electronically.2.&Getting HelpIf you have trouble with Spring Boot, we would like to help.Try the . They provide solutions to the most
common questions.Learn the Spring basics. Spring Boot builds on many other Spring projects. Check the
web-site for a wealth of reference documentation. If you are
starting out with Spring, try one of the .Ask a question. We monitor
for questions
tagged with .Report bugs with Spring Boot at .NoteAll of Spring Boot is open source, including the documentation. If you find
problems with the docs or if you want to improve them, please .3.&First StepsIf you are getting started with Spring Boot or 'Spring' in general, start with
:From scratch:
Running your example:
4.&Working with Spring BootReady to actually start using Spring Boot? :Build systems:
Best practices:
Running your code
Packaging your app:
Spring Boot CLI:
5.&Learning about Spring Boot FeaturesNeed more details about Spring Boot’s core features?
:Core Features:
Web Applications:
Working with data:
Messaging:
Extending:
6.&Moving to ProductionWhen you are ready to push your Spring Boot application to production, we have
that you might like:Management endpoints:
Connection options:
Monitoring:
7.&Advanced TopicsFinally, we have a few topics for more advanced users:Spring Boot Applications Deployment:
Build tool plugins:
Part&II.&Getting StartedIf 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
principles as we go.8.&Introducing Spring BootSpring 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.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
runs “spring scripts”.Our primary goals are:Provide a radically faster and widely accessible getting-started experience for all
Spring development.Be opinionated out of the box but get out of the way quickly as requirements start to
diverge from the defaults.Provide a range of non-functional features that are common to large classes of projects
(such as embedded servers, security, metrics, health checks, and externalized
configuration).Absolutely no code generation and no requirement for XML configuration.9.&System RequirementsSpring Boot 2.1.0.BUILD-SNAPSHOT requires
or above. Explicit build support is
provided for Maven 3.2+ and Gradle 4.9.1&Servlet ContainersSpring Boot supports the following embedded servlet containers:You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.10.&Installing Spring BootSpring Boot can be used with “classic” Java development tools or installed as a command
line tool. Either way, you need
or higher. Before you
begin, you should check your current Java installation by using the following command:$ java -versionIf you are new to Java development or if you want to experiment with Spring Boot, you
might want to try the
Line Interface) first. Otherwise, read on for “classic” installation instructions.10.1&Installation Instructions for the Java DeveloperYou 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.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).10.1.1&Maven InstallationSpring Boot is compatible with Apache Maven 3.2 or above. If you do not already have
Maven installed, you can follow the instructions at .TipOn 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
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 .
Spring Boot also provides an optional
executable jars.The following listing shows a typical pom.xml file:&?xml version="1.0" encoding="UTF-8"?&
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
com.example
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.1.0.BUILD-SNAPSHOT
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-maven-plugin
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
TipThe 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
for an alternative solution that uses an import
scope.10.1.2&Gradle InstallationSpring Boot is compatible with Gradle 4. If you do not already have Gradle installed, you
can follow the instructions at .Spring Boot dependencies can be declared by using the org.springframework.boot group.
Typically, your project declares dependencies to one or more
. Spring Boot
provides a useful
that can be used to simplify dependency declarations and to create executable
jars.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
for details.The following example shows a typical build.gradle file:buildscript {
repositories {
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.0.BUILD-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
baseName = 'myproject'
'0.0.1-SNAPSHOT'
repositories {
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}10.2&Installing the Spring Boot CLIThe Spring Boot CLI (Command Line Interface) is a command line tool that you can use to
quickly prototype with Spring. It lets you run
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.10.2.1&Manual InstallationYou can download the Spring CLI distribution from the Spring software repository:Cutting edge
are also available.Once downloaded, follow the
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
classpath is set correctly).10.2.2&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
and install Spring Boot by using the following
commands:$ sdk install springboot
$ spring --version
Spring Boot v2.1.0.BUILD-SNAPSHOTIf you develop features for the CLI and want easy access to the version you built,
use the following commands:$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin/spring-2.1.0.BUILD-SNAPSHOT/
$ sdk default springboot dev
$ spring --version
Spring CLI v2.1.0.BUILD-SNAPSHOTThe 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:$ sdk ls springboot
================================================================================
Available Springboot Versions
================================================================================
* 2.1.0.BUILD-SNAPSHOT
================================================================================
+ - local version
* - installed
& - currently in use
================================================================================10.2.3&OSX Homebrew InstallationIf you are on a Mac and use , you can install the Spring Boot
CLI by using the following commands:$ brew tap pivotal/tap
$ brew install springbootHomebrew installs spring to /usr/local/bin.NoteIf you do not see the formula, your installation of brew might be out-of-date. In
that case, run brew update and try again.10.2.4&MacPorts InstallationIf you are on a Mac and use , you can install the
Spring Boot CLI by using the following command:$ sudo port install spring-boot-cli10.2.5&Command-line CompletionThe Spring Boot CLI includes scripts that provide command completion for the
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
/shell-completion/bash and all scripts in that directory are executed when a new shell
starts. For example, to run the script manually if you have installed by using SDKMAN!,
use the following commands:$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
$ spring &HIT TAB HERE&
versionNoteIf you install the Spring Boot CLI by using Homebrew or MacPorts, the command-line
completion scripts are automatically registered with your shell.10.2.6&Windows Scoop InstallationIf you are on a Windows and use , you can install the Spring Boot
CLI by using the following commands:& scoop bucket add extras
& scoop install springbootScoop installs spring to ~/scoop/apps/springboot/current/bin.NoteIf you do not see the app manifest, your installation of scoop might be out-of-date.
In that case, run scoop update and try again.10.2.7&Quick-start Spring CLI ExampleYou can use the following web application to test your installation. To start, create a
file called app.groovy, as follows:@RestController
class ThisWillActuallyRun {
@RequestMapping("/")
String home() {
"Hello World!"
}Then run it from a shell, as follows:$ spring run app.groovyNoteThe first run of your application is slow, as dependencies are downloaded.
Subsequent runs are much quicker.Open
in your favorite web browser. You should see the following
output:Hello World!10.3&Upgrading from an Earlier Version of Spring BootIf you are upgrading from an earlier release of Spring Boot, check the
that provides detailed upgrade instructions. Check also the
for a list of “new and noteworthy” features for each
release.When upgrading to a new feature release, some properties may have been renamed or removed.
Spring Boot provides a way to analyze your application’s environment and print diagnostics
at startup, but also temporarily migrate properties at runtime for you. To enable that
feature, add the following dependency to your project:
org.springframework.boot
spring-boot-properties-migrator
Warningproperties that are added late to the environment, such as when using
@PropertySource, will not be taken into account.NoteOnce you’re done with the migration, please make sure to remove this module from
your project’s dependencies.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
, remembering to update
your PATH environment variable to remove any older references.11.&Developing Your First Spring Boot ApplicationThis section describes how to develop a simple “Hello World!” web application that
highlights some of Spring Boot’s key features. We use Maven to build this project, since
most IDEs support it.TipThe
web site contains many “Getting Started”
that use Spring Boot. If you need to solve a specific
problem, check there first.You can shortcut the steps below by going to
and choosing the
"Web" starter from the dependencies searcher. Doing so generates a new project structure
so that you can . Check
details.Before we begin, open a terminal and run the following commands to ensure that you have
valid versions of Java and Maven installed:$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)$ mvn -v
Apache Maven 3.3.9 (bb52da5a3f4c23dc5; T16:41:47+00:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_102, vendor: Oracle CorporationNoteThis sample needs to be created in its own folder. Subsequent instructions assume
that you have created a suitable folder and that it is your current directory.11.1&Creating the POMWe 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:&?xml version="1.0" encoding="UTF-8"?&
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
com.example
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.1.0.BUILD-SNAPSHOT
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
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).NoteAt 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.11.2&Adding Classpath DependenciesSpring 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
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:$ mvn dependency:tree
[INFO] com.example:myproject:jar:0.0.1-SNAPSHOTThe 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
spring-boot-starter-web dependency immediately below the parent section:
org.springframework.boot
spring-boot-starter-web
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.11.3&Writing the CodeTo finish our application, we need to create a single Java file. By default, Maven
compiles sources from src/main/java, so you need to create that folder structure and
then add a file named src/main/java/Example.java to contain the following code:import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping("/")
String home() {
return "Hello World!";
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}Although there is not much code here, quite a lot is going on. We step through the
important parts in the next few sections.11.3.1&The @RestController and @RequestMapping AnnotationsThe first annotation on our Example class is @RestController. This is known as a
stereotype annotation. It provides hints for people reading the code and for Spring
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.TipThe @RestController and @RequestMapping annotations are Spring MVC annotations.
(They are not specific to Spring Boot.) See the
in the Spring Reference Documentation for more details.11.3.2&The @EnableAutoConfiguration AnnotationThe 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.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. Spring Boot still does its best to auto-configure your application.11.3.3&The “main” MethodThe 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.11.4&Running the ExampleAt this point, your application should work. Since you used the
spring-boot-starter-parent POM, you have a useful run goal that you can use to start
the application. Type mvn spring-boot:run from the root project directory to start the
application. You should see output similar to the following:$ mvn spring-boot:run
/\\ / ___'_ __ _ _(_)_ __
__ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
___)| |_)| | | | | || (_| |
|____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
(v2.1.0.BUILD-SNAPSHOT)
....... . . .
....... . . . (log output here)
....... . . .
........ Started Example in 2.222 seconds (JVM running for 6.514)If you open a web browser to , you should see the following output:Hello World!To gracefully exit the application, press ctrl-c.11.5&Creating an Executable JarWe finish our example by creating a completely self-contained executable jar file that
we could run in production. Executable jars (sometimes called “fat jars”) are archives
containing your compiled classes along with all of the jar dependencies that your code
needs to run.Java does not provide a standard way to load nested jar files (jar files that are
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
multiple jars.Spring Boot takes a
and lets you actually nest jars directly.To create an executable jar, we need to add the spring-boot-maven-plugin to our
pom.xml. To do so, insert the following lines just below the dependencies section:
org.springframework.boot
spring-boot-maven-plugin
NoteThe 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
for details.Save your pom.xml and run mvn package from the command line, as follows:$ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] .... ..
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject ---
[INFO] Building jar: /Users/developer/example/spring-boot-example/target/myproject-0.0.1-SNAPSHOT.jar
[INFO] --- spring-boot-maven-plugin:2.1.0.BUILD-SNAPSHOT:repackage (default) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------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:$ jar tvf target/myproject-0.0.1-SNAPSHOT.jarYou 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:$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
/\\ / ___'_ __ _ _(_)_ __
__ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
___)| |_)| | | | | || (_| |
|____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
(v2.1.0.BUILD-SNAPSHOT)
....... . . .
....... . . . (log output here)
....... . . .
........ Started Example in 2.536 seconds (JVM running for 2.864)As before, to exit the application, press ctrl-c.12.&What to Read NextHopefully, 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
and check out some of the
guides that solve specific “How do I do that
with Spring?” problems. We also have Spring Boot-specific
“” reference documentation.The
also has a
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).Otherwise, the next logical step is to read . If
you are really impatient, you could also jump ahead and read about
.Part&III.&Using Spring BootThis 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
recommendations that, when followed, make your development process a little easier.If you are starting out with Spring Boot, you should probably read the
guide before diving into this
section.13.&Build SystemsIt is strongly recommended that you choose a build system that supports
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.13.1&Dependency ManagementEach 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 manages that for you. When you upgrade Spring
Boot itself, these dependencies are upgraded as well in a consistent way.NoteYou 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
that can be used with both
.WarningEach release of Spring Boot is associated with a base version of the Spring
Framework. We highly recommend that you not specify its version.13.2&MavenMaven users can inherit from the spring-boot-starter-parent project to obtain sensible
defaults. The parent project provides the following features:Java 1.8 as the default compiler level.UTF-8 source encoding.A , 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
.Sensible plugin configuration (,
).Sensible resource filtering for application.properties and application.yml
including profile-specific files (for example, application-dev.properties and
application-dev.yml)Note that, since the application.properties and application.yml files accept Spring
style placeholders (${…​}), the Maven filtering is changed to use @ placeholders.
(You can override that by setting a Maven property called resource.delimiter.)13.2.1&Inheriting the Starter ParentTo configure your project to inherit from the spring-boot-starter-parent, set the
parent as follows:
org.springframework.boot
spring-boot-starter-parent
2.1.0.BUILD-SNAPSHOT
NoteYou should need to specify only the Spring Boot version number on this dependency.
If you import additional starters, you can safely omit the version number.With that setup, you can also override individual dependencies by overriding a property
in your own project. For instance, to upgrade to another Spring Data release train, you
would add the following to your pom.xml:
Fowler-SR2
TipCheck the
for a list of supported properties.13.2.2&Using Spring Boot without the Parent POMNot 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:
org.springframework.boot
spring-boot-dependencies
2.1.0.BUILD-SNAPSHOT
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:
org.springframework.data
spring-data-releasetrain
Fowler-SR2
org.springframework.boot
spring-boot-dependencies
2.1.0.BUILD-SNAPSHOT
NoteIn the preceding example, we specify a BOM, but any dependency type can be
overridden in the same way.13.2.3&Using the Spring Boot Maven PluginSpring Boot includes a
that can package the project as an executable jar. Add the plugin to your
&plugins& section if you want to use it, as shown in the following example:
org.springframework.boot
spring-boot-maven-plugin
NoteIf you use the Spring Boot starter parent pom, you need to add only the plugin.
There is no need to configure it unless you want to change the settings defined in the
parent.13.3&GradleTo learn about using Spring Boot with Gradle, please refer to the documentation for
Spring Boot’s Gradle plugin:Reference ( and
)13.4&AntIt is possible to build a Spring Boot project using Apache Ant+Ivy. The
spring-boot-antlib “AntLib” module is also available to help Ant create executable
jars.To declare dependencies, a typical ivy.xml file looks something like the following
example: version="2.0"
organisation="org.springframework.boot" module="spring-boot-sample-ant"
name="compile" description="everything needed to compile this module"
name="runtime" extends="compile" description="everything needed to run this module"
org="org.springframework.boot" name="spring-boot-starter"
rev="${spring-boot.version}" conf="compile"
A typical build.xml looks like the following example:
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:spring-boot="antlib:org.springframework.boot.ant"
name="myapp" default="build"
name="spring-boot.version" value="2.1.0.BUILD-SNAPSHOT"
name="resolve" description="--& retrieve dependencies with ivy"
pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]"
name="classpaths" depends="resolve"
id="compile.classpath"
dir="lib/compile" includes="*.jar"
name="init" depends="classpaths"
dir="build/classes"
name="compile" depends="init" description="compile"
srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath"
name="build" depends="compile"
destfile="build/myapp.jar" classes="build/classes"
dir="lib/runtime"
TipIf you do not want to use the spring-boot-antlib module, see the
“How-to” .13.5&StartersStarters are a set of convenient dependency descriptors that you can include in your
application. You get a one-stop shop for all the Spring and related technologies that you
need without having to hunt through sample code and copy-paste loads of dependency
descriptors. For example, if you want to get started using Spring and JPA for database
access, include the spring-boot-starter-data-jpa dependency in your project.The starters contain a lot of the dependencies that you need to get a project up and
running quickly and with a consistent, supported set of managed transitive dependencies.All official starters follow a si spring-boot-starter-*,
where * is a particular type of application. This naming structure is intended to
help when you need to find a starter. The Maven integration in many IDEs lets you
search dependencies by name. For example, with the appropriate Eclipse or STS plugin
installed, you can press ctrl-space in the POM editor and type
“spring-boot-starter” for a complete list.As explained in the “” 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.The following application starters are provided by Spring Boot under the
org.springframework.boot group:Table&13.1.&Spring Boot application startersNameDescriptionPomspring-boot-starterCore starter, including auto-configuration support, logging and YAMLspring-boot-starter-activemqStarter for JMS messaging using Apache ActiveMQspring-boot-starter-amqpStarter for using Spring AMQP and Rabbit MQspring-boot-starter-aopStarter for aspect-oriented programming with Spring AOP and AspectJspring-boot-starter-artemisStarter for JMS messaging using Apache Artemisspring-boot-starter-batchStarter for using Spring Batchspring-boot-starter-cacheStarter for using Spring Framework’s caching supportspring-boot-starter-cloud-connectorsStarter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Herokuspring-boot-starter-data-cassandraStarter for using Cassandra distributed database and Spring Data Cassandraspring-boot-starter-data-cassandra-reactiveStarter for using Cassandra distributed database and Spring Data Cassandra Reactivespring-boot-starter-data-couchbaseStarter for using Couchbase document-oriented database and Spring Data Couchbasespring-boot-starter-data-couchbase-reactiveStarter for using Couchbase document-oriented database and Spring Data Couchbase Reactivespring-boot-starter-data-elasticsearchStarter for using Elasticsearch search and analytics engine and Spring Data Elasticsearchspring-boot-starter-data-jpaStarter for using Spring Data JPA with Hibernatespring-boot-starter-data-ldapStarter for using Spring Data LDAPspring-boot-starter-data-mongodbStarter for using MongoDB document-oriented database and Spring Data MongoDBspring-boot-starter-data-mongodb-reactiveStarter for using MongoDB document-oriented database and Spring Data MongoDB Reactivespring-boot-starter-data-neo4jStarter for using Neo4j graph database and Spring Data Neo4jspring-boot-starter-data-redisStarter for using Redis key-value data store with Spring Data Redis and the Lettuce clientspring-boot-starter-data-redis-reactiveStarter for using Redis key-value data store with Spring Data Redis reactive and the Lettuce clientspring-boot-starter-data-restStarter for exposing Spring Data repositories over REST using Spring Data RESTspring-boot-starter-data-solrStarter for using the Apache Solr search platform with Spring Data Solrspring-boot-starter-freemarkerStarter for building MVC web applications using FreeMarker viewsspring-boot-starter-groovy-templatesStarter for building MVC web applications using Groovy Templates viewsspring-boot-starter-hateoasStarter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOASspring-boot-starter-integrationStarter for using Spring Integrationspring-boot-starter-jdbcStarter for using JDBC with the HikariCP connection poolspring-boot-starter-jerseyStarter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-jooqStarter for using jOOQ to access SQL databases. An alternative to
or spring-boot-starter-jsonStarter for reading and writing jsonspring-boot-starter-jta-atomikosStarter for JTA transactions using Atomikosspring-boot-starter-jta-bitronixStarter for JTA transactions using Bitronixspring-boot-starter-jta-narayanaStarter for JTA transactions using Narayanaspring-boot-starter-mailStarter for using Java Mail and Spring Framework’s email sending supportspring-boot-starter-mustacheStarter for building web applications using Mustache viewsspring-boot-starter-quartzStarter for using the Quartz schedulerspring-boot-starter-securityStarter for using Spring Securityspring-boot-starter-testStarter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockitospring-boot-starter-thymeleafStarter for building MVC web applications using Thymeleaf viewsspring-boot-starter-validationStarter for using Java Bean Validation with Hibernate Validatorspring-boot-starter-webStarter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded containerspring-boot-starter-web-servicesStarter for using Spring Web Servicesspring-boot-starter-webfluxStarter for building WebFlux applications using Spring Framework’s Reactive Web supportspring-boot-starter-websocketStarter for building WebSocket applications using Spring Framework’s WebSocket supportIn addition to the application starters, the following starters can be used to add
features:Table&13.2.&Spring Boot production startersNameDescriptionPomspring-boot-starter-actuatorStarter for using Spring Boot’s Actuator which provides production ready features to help you monitor and manage your applicationFinally, Spring Boot also includes the following starters that can be used if you want to
exclude or swap specific technical facets:Table&13.3.&Spring Boot technical startersNameDescriptionPomspring-boot-starter-jettyStarter for using Jetty as the embedded servlet container. An alternative to spring-boot-starter-log4j2Starter for using Log4j2 for logging. An alternative to spring-boot-starter-loggingStarter for logging using Logback. Default logging starterspring-boot-starter-reactor-nettyStarter for using Reactor Netty as the embedded reactive HTTP server.spring-boot-starter-tomcatStarter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-undertowStarter for using Undertow as the embedded servlet container. An alternative to TipFor a list of additional community contributed starters, see the
the spring-boot-starters module on GitHub.14.&Structuring Your CodeSpring Boot does not require any specific code layout to work. However, there are some
best practices that help.14.1&Using the “default” PackageWhen 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.TipWe recommend that you follow Java’s recommended package naming conventions and use a
reversed domain name (for example, com.example.project).14.2&Locating the Main Application ClassWe generally recommend that you locate your main application class in a root package
above other classes. The
is often placed on your main class, and it
implicitly defines a base “search package” for certain items. For example, if you are
writing a JPA application, the package of the @SpringBootApplication annotated class
is used to search for @Entity items. Using a root package also allows component
scan to apply only on your project.TipIf you don’t want to use @SpringBootApplication, the @EnableAutoConfiguration
and @ComponentScan annotations that it imports defines that behaviour so you can also
use that instead.The following listing shows a typical layout:com
+- example
+- myapplication
+- Application.java
+- customer
+- Customer.java
+- CustomerController.java
+- CustomerService.java
+- CustomerRepository.java
+- Order.java
+- OrderController.java
+- OrderService.java
+- OrderRepository.javaThe Application.java file would declare the main method, along with the basic
@SpringBootApplication, as follows:package com.example.
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}15.&Configuration ClassesSpring 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.TipMany Spring configuration examples have been published on the Internet that use XML
configuration. If possible, always try to use the equivalent Java-based configuration.
Searching for Enable* annotations can be a good starting point.15.1&Importing Additional Configuration ClassesYou need not put all your @Configuration into a single class. The @Import annotation
can be used to import additional configuration classes. Alternatively, you can use
@ComponentScan to automatically pick up all Spring components, including
@Configuration classes.15.2&Importing XML ConfigurationIf you absolutely must use XML based configuration, we recommend that you still start
with a @Configuration class. You can then use an @ImportResource annotation to load
XML configuration files.16.&Auto-configurationSpring 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.You need to opt-in to auto-configuration by adding the @EnableAutoConfiguration or
@SpringBootApplication annotations to one of your @Configuration classes.TipYou should only ever add one @SpringBootApplication or @EnableAutoConfiguration
annotation. We generally recommend that you add one or the other to your primary
@Configuration class only.16.1&Gradually Replacing Auto-configurationAuto-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 a conditions report to the console.16.2&Disabling Specific Auto-configuration ClassesIf you find that specific auto-configuration classes that you do not want are being
applied, you can use the exclude attribute of @EnableAutoConfiguration to disable them,
as shown in the following example:import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}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.TipYou can define exclusions both at the annotation level and by using the property.17.&Spring Beans and Dependency InjectionYou 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.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
components (@Component, @Service, @Repository, @Controller etc.) are
automatically registered as Spring Beans.The following example shows a @Service Bean that uses constructor injection to obtain a
required RiskAssessor bean:package com.example.
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.S
public class DatabaseAccountService implements AccountService {
private final RiskAssessor riskA
@Autowired
public DatabaseAccountService(RiskAssessor riskAssessor) {
this.riskAssessor = riskA
}If a bean has one constructor, you can omit the @Autowired, as shown in the following
example:@Service
public class DatabaseAccountService implements AccountService {
private final RiskAssessor riskA
public DatabaseAccountService(RiskAssessor riskAssessor) {
this.riskAssessor = riskA
}TipNotice how using constructor injection lets the riskAssessor field be marked as
final, indicating that it cannot be subsequently changed.18.&Using the @SpringBootApplication AnnotationMany Spring Boot developers like their apps to use auto-configuration, component scan and
be able to define extra configuration on their "application class". A single
@SpringBootApplication annotation can be used to enable those three features, that is:@EnableAutoConfiguration: enable @ComponentScan: enable @Component scan on the package where the application is
located (see )@Configuration: allow to register extra beans in the context or import additional
configuration classesThe @SpringBootApplication annotation is equivalent to using @Configuration,
@EnableAutoConfiguration, and @ComponentScan with their default attributes, as shown
in the following example:package com.example.
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}Note@SpringBootApplication also provides aliases to customize the attributes of
@EnableAutoConfiguration and @ComponentScan.NoteNone of these features are mandatory and you may chose to replace this single annotation
by any of the features that it enables. For instance, you may not want to use component
scan in your application:package com.example.
import org.springframework.boot.SpringA
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.C
import org.springframework.context.annotation.I
@Configuration
@EnableAutoConfiguration
@Import({ MyConfig.class, MyAnotherConfig.class })
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}In this example, Application is just like any other Spring Boot application except that
@Component-annotated classes are not detected automatically and the user-defined beans
are imported explicitly (see @Import).19.&Running Your ApplicationOne 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.NoteThis 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.19.1&Running from an IDEYou 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
. Gradle offers plugins for
.TipIf 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.19.2&Running as a Packaged ApplicationIf you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can
run your application using java -jar, as shown in the following example:$ java -jar target/myapplication-0.0.1-SNAPSHOT.jarIt is also possible to run a packaged application with remote debugging support enabled.
Doing so lets you attach a debugger to your packaged application, as shown in the
following example:$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myapplication-0.0.1-SNAPSHOT.jar19.3&Using the Maven PluginThe Spring Boot Maven plugin includes a run goal that can be used to quickly compile
and run your application. Applications run in an exploded form, as they do in your IDE.
The following example shows a typical Maven command to run a Spring Boot application:$ mvn spring-boot:runYou might also want to use the MAVEN_OPTS operating system environment variable, as
shown in the following example:$ export MAVEN_OPTS=-Xmx1024m19.4&Using the Gradle PluginThe 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:$ gradle bootRunYou might also want to use the JAVA_OPTS operating system environment variable, as
shown in the following example:$ export JAVA_OPTS=-Xmx1024m19.5&Hot SwappingSince Spring Boot applications are just plain Java applications, JVM hot-swapping should
work out of the box. JVM hot swapping is somewhat limited with the bytecode that it can
replace. For a more complete solution,
can be used.The
spring-boot-devtools module also includes support for quick application restarts.
section later in this chapter and the
for details.20.&Developer ToolsSpring Boot includes an additional set of tools that can make the application
development experience a little more pleasant. The spring-boot-devtools module can be
included in any project to provide additional development-time features. To include
devtools support, add the module dependency to your build, as shown in the following
listings for Maven and Gradle:Maven.&
org.springframework.boot
spring-boot-devtools
dependencies {
compile("org.springframework.boot:spring-boot-devtools")
NoteDeveloper tools are automatically disabled when running a fully packaged
application. If your application is launched from java -jar or if it is started from a
special classloader, then it is considered a “production application”. Flagging the
dependency as optional in Maven or using compileOnly in Gradle is a best practice that
prevents devtools from being transitively applied to other modules that use your project.TipRepackaged archives do not contain devtools by default. If you want to use a
, you need to disable the
excludeDevtools build property to include it. The property is supported with both the
Maven and Gradle plugins.20.1&Property DefaultsSeveral of the libraries supported by Spring Boot use caches to improve performance. For
cache compiled templates to avoid repeatedly parsing template files. Also,
Spring MVC can add HTTP caching headers to responses when serving static resources.While caching is very beneficial in production, it can be counter-productive during
development, preventing you from seeing the changes you just made in your application.
For this reason, spring-boot-devtools disables the caching options by default.Cache options are usually configured by settings in your application.properties file.
For example, Thymeleaf offers the spring.thymeleaf.cache property. Rather than needing
to set these properties manually, the spring-boot-devtools module automatically applies
sensible development-time configuration.TipFor a complete list of the properties that are applied by the devtools, see
.20.2&Automatic RestartApplications 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, .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 -& Build Project) has the same effect.NoteAs 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.TipAutomatic restart works very well when used with LiveReload.
for details. If you use
JRebel, automatic restarts are disabled in favor of dynamic class reloading. Other
devtools features (such as LiveReload and property overrides) can still be used.NoteDevTools relies on the application context’s shutdown hook to close it during a
restart. It does not work correctly if you have disabled the shutdown hook
(SpringApplication.setRegisterShutdownHook(false)).NoteWhen 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.NoteDevTools needs to customize the ResourceLoader used by the ApplicationContext.
If your application provides one already, it is going to be wrapped. Direct override of
the getResource method on the ApplicationContext is not supported.The restart technology provided by Spring Boot works by using two classloaders. Classes
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
populated.If you find that restarts are not quick enough for your applications or you encounter
classloading issues, you could consider reloading technologies such as
from ZeroTurnaround. These work by
rewriting classes as they are loaded to make them more amenable to reloading.20.2.1&Logging changes in condition evaluationBy default, each time your application restarts, a report showing the condition evaluation
delta is logged. The report shows the changes to your application’s auto-configuration as
you make changes such as adding or removing beans and setting configuration properties.To disable the logging of the report, set the following property:spring.devtools.restart.log-condition-evaluation-delta=false20.2.2&Excluding ResourcesCertain resources do not necessarily need to trigger a restart when they are changed. For
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
. 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:spring.devtools.restart.exclude=static/**,public/**TipIf you want to keep those defaults and add additional exclusions, use the
spring.devtools.restart.additional-exclude property instead.20.2.3&Watching Additional PathsYou 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
to control whether changes
beneath the additional paths trigger a full restart or a
.20.2.4&Disabling RestartIf 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).If you need to completely disable restart support (for example, because it does not 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:public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApp.class, args);
}20.2.5&Using a Trigger FileIf 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 only occurs 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.TipYou might want to set spring.devtools.restart.trigger-file as a
, so that all your projects behave
in the same way.20.2.6&Customizing the Restart ClassloaderAs described earlier in the
section, restart
functionality is implemented by using two classloaders. For most applications, this
approach works well. However, it can sometimes cause classloading issues.By default, any open project in your IDE is loaded with the “restart” classloader, and
any regular .jar file is loaded with the “base” classloader. If you work on a
multi-module project, and not every module is imported into your IDE, you may need to
customize things. To do so, you can create a META-INF/spring-devtools.properties file.The spring-devtools.properties file can contain properties prefixed with
restart.exclude and restart.include. The include elements are items that should be
pulled up into the “restart” classloader, and the exclude elements are items that
should be pushed down into the “base” classloader. The value of the property is a regex
pattern that is applied to the classpath, as shown in the following example:restart.exclude.companycommonlibs=/mycorp-common-[\\w-]+\.jar
restart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jarNoteAll property keys must be unique. As long as a property starts with
restart.include. or restart.exclude. it is considered.TipAll META-INF/spring-devtools.properties from the classpath are loaded. You can
package files inside your project, or in the libraries that the project consumes.20.2.7&Known LimitationsRestart functionality does not work well with objects that are deserialized by using a
standard ObjectInputStream. If you need to deserialize data, you may need to use
Spring’s ConfigurableObjectInputStream in combination with
Thread.currentThread().getContextClassLoader().Unfortunately, several third-party libraries deserialize without considering the context
classloader. If you find such a problem, you need to request a fix with the original
authors.20.3&LiveReloadThe 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
.If you do not want to start the LiveReload server when your application runs, you can set
the spring.devtools.livereload.enabled property to false.NoteYou can only run one LiveReload server at a time. Before starting your application,
ensure that no other LiveReload servers are running. If you start multiple applications
from your IDE, only the first has LiveReload support.20.4&Global SettingsYou can configure global devtools settings by adding a file named
.spring-boot-devtools.properties to your $HOME folder (note that the filename starts
with “.”). Any properties added to this file apply to all Spring Boot applications on
your machine that use devtools. For example, to configure restart to always use a
, you would add the following
property:~/.spring-boot-devtools.properties.&
spring.devtools.reload.trigger-file=.reloadtrigger
20.5&Remote ApplicationsThe Spring Boot developer tools are not 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:
org.springframework.boot
spring-boot-maven-plugin
Then you need to set a spring.devtools.remote.secret property, as shown in the
following example:spring.devtools.remote.secret=mysecretWarningEnabling spring-boot-devtools on a remote application is a security risk. You
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.20.5.1&Running the Remote Client ApplicationThe remote client application is designed to be run from within your IDE. You need to run
org.springframework.boot.devtools.RemoteSpringApplication with the same classpath as
the remote project that you connect to. The application’s single required argument is the
remote URL to which it connects.For example, if you are using Eclipse or STS and you have a project named my-app that
you have deployed to Cloud Foundry, you would do the following:Select Run Configurations…​ from the Run menu.Create a new Java Application “launch configuration”.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).A running remote client might resemble the following listing:
/\\ / ___'_ __ _ _(_)_ __
( ( )\___ | '_ | '_| | '_ \/ _` |
| _ \___ _ __
___| |_ ___ \ \ \ \
___)| |_)| | | | | || (_| []::::::[]
_/ -_) ) ) ) )
|____| .__|_| |_|_| |_\__, |
|_|_\___|_|_|_\___/\__\___|/ / / /
=========|_|==============|___/===================================/_/_/_/
:: Spring Boot Remote :: 2.1.0.BUILD-SNAPSHOT
18:25:06.632
INFO 14938 --- [
main] o.s.b.devtools.RemoteSpringApplication
: Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code/spring-boot-samples/spring-boot-sample-devtools)
18:25:06.671
INFO 14938 --- [
main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
18:25:07.043
WARN 14938 --- [
main] o.s.b.d.r.c.RemoteClientConfiguration
: The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
18:25:07.074
INFO 14938 --- [
main] o.s.b.d.a.OptionalLiveReloadServer
: LiveReload server is running on port 35729
18:25:07.130
INFO 14938 --- [
main] o.s.b.devtools.RemoteSpringApplication
: Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)NoteBecause the remote client is using the same classpath as the real application it
can directly read application properties. This is how the spring.devtools.remote.secret
property is read and passed to the server for authentication.TipIt is always advisable to use https:// as the connection protocol, so that traffic
is encrypted and passwords cannot be intercepted.TipIf you need to use a proxy to access the remote application, configure the
spring.devtools.remote.proxy.host and spring.devtools.remote.proxy.port properties.20.5.2&Remote UpdateThe remote client monitors your application classpath for changes in the same way as the
. Any updated resource is pushed to the
remote application and (if required) triggers a restart. This can be helpful if you
iterate on a feature that uses a cloud service that you do not have locally. Generally,
remote updates and restarts are much quicker than a full rebuild and deploy cycle.NoteFiles are only monitored when the remote client is running. If you change a file
before starting the remote client, it is

我要回帖

更多关于 crazy box是什么 的文章

 

随机推荐