Update reference documentation for Spring Boot 1.2
Various updates and polish to prepare the reference documentation for Spring Boot 1.2. Fixes gh-1903
This commit is contained in:
parent
a0ce04ac4b
commit
e772174019
|
@ -17,7 +17,7 @@ unsupported build system. If you are just getting started, you might want to rea
|
||||||
== Spring Boot Maven plugin
|
== Spring Boot Maven plugin
|
||||||
The {spring-boot-maven-plugin-site}/[Spring Boot Maven Plugin] provides Spring Boot
|
The {spring-boot-maven-plugin-site}/[Spring Boot Maven Plugin] provides Spring Boot
|
||||||
support in Maven, allowing you to package executable jar or war archives and run an
|
support in Maven, allowing you to package executable jar or war archives and run an
|
||||||
application "`in-place`". To use it you must be using Maven 3 (or better).
|
application "`in-place`". To use it you must be using Maven 3.2 (or better).
|
||||||
|
|
||||||
NOTE: Refer to the {spring-boot-maven-plugin-site}/[Spring Boot Maven Plugin Site]
|
NOTE: Refer to the {spring-boot-maven-plugin-site}/[Spring Boot Maven Plugin Site]
|
||||||
for complete plugin documentation.
|
for complete plugin documentation.
|
||||||
|
|
|
@ -135,9 +135,9 @@ access application information (such as the public URL of the application) and s
|
||||||
information (such as database credentials). See `VcapApplicationListener` Javdoc for
|
information (such as database credentials). See `VcapApplicationListener` Javdoc for
|
||||||
complete details.
|
complete details.
|
||||||
|
|
||||||
TIP: The https://github.com/spring-projects/spring-cloud[Spring Cloud] project is a better
|
TIP: The http://cloud.spring.io/spring-cloud-connectors/[Spring Cloud Connectors] project
|
||||||
fit for tasks such as configuring a DataSource; it also lets you use Spring Cloud with
|
is a better fit for tasks such as configuring a DataSource. Spring Boot includes
|
||||||
Heroku.
|
auto-configuration support and a `spring-boot-starter-cloud-connectors` starter POM.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ This should be everything you need. The most common workflow for Heroku deployme
|
||||||
|
|
||||||
-----> Java app detected
|
-----> Java app detected
|
||||||
-----> Installing OpenJDK 1.7... *done*
|
-----> Installing OpenJDK 1.7... *done*
|
||||||
-----> Installing Maven 3.0.3... *done*
|
-----> Installing Maven 3.2.3... *done*
|
||||||
-----> Installing settings.xml... *done*
|
-----> Installing settings.xml... *done*
|
||||||
-----> executing /app/tmp/cache/.maven/bin/mvn -B
|
-----> executing /app/tmp/cache/.maven/bin/mvn -B
|
||||||
-Duser.home=/tmp/build_0c35a5d2-a067-4abc-a232-14b1fb7a8229
|
-Duser.home=/tmp/build_0c35a5d2-a067-4abc-a232-14b1fb7a8229
|
||||||
|
|
|
@ -109,7 +109,7 @@ build tool that supports dependency management (such as Maven or Gradle).
|
||||||
|
|
||||||
[[getting-started-maven-installation]]
|
[[getting-started-maven-installation]]
|
||||||
==== Maven installation
|
==== Maven installation
|
||||||
Spring Boot is compatible with Apache Maven 3.0 or above. If you don't already have Maven
|
Spring Boot is compatible with Apache Maven 3.2 or above. If you don't already have Maven
|
||||||
installed you can follow the instructions at http://maven.apache.org.
|
installed you can follow the instructions at http://maven.apache.org.
|
||||||
|
|
||||||
TIP: On many operating systems Maven can be installed via a package manager. If you're an
|
TIP: On many operating systems Maven can be installed via a package manager. If you're an
|
||||||
|
@ -199,7 +199,7 @@ scope.
|
||||||
|
|
||||||
[[getting-started-gradle-installation]]
|
[[getting-started-gradle-installation]]
|
||||||
==== Gradle installation
|
==== Gradle installation
|
||||||
Spring Boot is compatible with Gradle 1.6 or above. If you don't already have Gradle
|
Spring Boot is compatible with Gradle 1.12 or above. If you don't already have Gradle
|
||||||
installed you can follow the instructions at http://www.gradle.org/.
|
installed you can follow the instructions at http://www.gradle.org/.
|
||||||
|
|
||||||
Spring Boot dependencies can be declared using the `org.springframework.boot` `group`.
|
Spring Boot dependencies can be declared using the `org.springframework.boot` `group`.
|
||||||
|
@ -449,7 +449,7 @@ installed.
|
||||||
[indent=0]
|
[indent=0]
|
||||||
----
|
----
|
||||||
$ mvn -v
|
$ mvn -v
|
||||||
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
|
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T13:58:10-07:00)
|
||||||
Maven home: /Users/user/tools/apache-maven-3.1.1
|
Maven home: /Users/user/tools/apache-maven-3.1.1
|
||||||
Java version: 1.7.0_51, vendor: Oracle Corporation
|
Java version: 1.7.0_51, vendor: Oracle Corporation
|
||||||
----
|
----
|
||||||
|
@ -511,7 +511,7 @@ endif::[]
|
||||||
----
|
----
|
||||||
|
|
||||||
This should give you a working build, you can test it out by running `mvn package` (you
|
This should give you a working build, you can test it out by running `mvn package` (you
|
||||||
can ignore the '"`jar will be empty - no content was marked for inclusion!'`"' warning for
|
can ignore the "`jar will be empty - no content was marked for inclusion!'`" warning for
|
||||||
now).
|
now).
|
||||||
|
|
||||||
NOTE: At this point you could import the project into an IDE (most modern Java IDE's
|
NOTE: At this point you could import the project into an IDE (most modern Java IDE's
|
||||||
|
@ -768,7 +768,7 @@ To run that application, use the `java -jar` command:
|
||||||
....... . . .
|
....... . . .
|
||||||
....... . . . (log output here)
|
....... . . . (log output here)
|
||||||
....... . . .
|
....... . . .
|
||||||
........ Started Example in 3.236 seconds (JVM running for 3.764)
|
........ Started Example in 2.536 seconds (JVM running for 2.864)
|
||||||
----
|
----
|
||||||
|
|
||||||
As before, to gracefully exit the application hit `ctrl-c`.
|
As before, to gracefully exit the application hit `ctrl-c`.
|
||||||
|
|
|
@ -2135,7 +2135,7 @@ Once the war is working we make it executable by adding a `main` method to our
|
||||||
|
|
||||||
Applications can fall into more than one category:
|
Applications can fall into more than one category:
|
||||||
|
|
||||||
* Servlet 3.0 applications with no `web.xml`.
|
* Servlet 3.0+ applications with no `web.xml`.
|
||||||
* Applications with a `web.xml`.
|
* Applications with a `web.xml`.
|
||||||
* Applications with a context hierarchy.
|
* Applications with a context hierarchy.
|
||||||
* Applications without a context hierarchy.
|
* Applications without a context hierarchy.
|
||||||
|
@ -2143,8 +2143,8 @@ Applications can fall into more than one category:
|
||||||
All of these should be amenable to translation, but each might require slightly different
|
All of these should be amenable to translation, but each might require slightly different
|
||||||
tricks.
|
tricks.
|
||||||
|
|
||||||
Servlet 3.0 applications might translate pretty easily if they already use the Spring
|
Servlet 3.0+ applications might translate pretty easily if they already use the Spring
|
||||||
Servlet 3.0 initializer support classes. Normally all the code from an existing
|
Servlet 3.0+ initializer support classes. Normally all the code from an existing
|
||||||
`WebApplicationInitializer` can be moved into a `SpringBootServletInitializer`. If your
|
`WebApplicationInitializer` can be moved into a `SpringBootServletInitializer`. If your
|
||||||
existing application has more than one `ApplicationContext` (e.g. if it uses
|
existing application has more than one `ApplicationContext` (e.g. if it uses
|
||||||
`AbstractDispatcherServletInitializer`) then you might be able to squash all your context
|
`AbstractDispatcherServletInitializer`) then you might be able to squash all your context
|
||||||
|
|
|
@ -155,10 +155,10 @@ in your `ApplicationContext`. Spring Boot includes a number of auto-configured
|
||||||
|
|
||||||
=== Security with HealthIndicators
|
=== Security with HealthIndicators
|
||||||
Information returned by `HealthIndicators` is often somewhat sensitive in nature. For
|
Information returned by `HealthIndicators` is often somewhat sensitive in nature. For
|
||||||
example and you probably don't want to publish details of your database server to the
|
example, you probably don't want to publish details of your database server to the
|
||||||
world. For this reason, by default, only the health status is exposed on an insecure HTTP
|
world. For this reason, by default, only the health status is exposed over an
|
||||||
connection. If you are happy for complete heath information to always be exposed you can
|
unauthenticated HTTP connection. If you are happy for complete heath information to always
|
||||||
set `endpoints.health.sensitive` to `false`.
|
be exposed you can set `endpoints.health.sensitive` to `false`.
|
||||||
|
|
||||||
Heath responses are also cached to prevent "`denial of service`" attacks. Use the
|
Heath responses are also cached to prevent "`denial of service`" attacks. Use the
|
||||||
`endpoints.health.time-to-live` property if you want to change the default cache period
|
`endpoints.health.time-to-live` property if you want to change the default cache period
|
||||||
|
@ -169,6 +169,7 @@ of 1000 milliseconds.
|
||||||
==== Auto-configured HealthIndicators
|
==== Auto-configured HealthIndicators
|
||||||
The following `HealthIndicators` are auto-configured by Spring Boot when appropriate:
|
The following `HealthIndicators` are auto-configured by Spring Boot when appropriate:
|
||||||
|
|
||||||
|
[cols="1,4"]
|
||||||
|===
|
|===
|
||||||
|Name |Description
|
|Name |Description
|
||||||
|
|
||||||
|
@ -220,9 +221,9 @@ additional details to be displayed.
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
In addition to Spring Boot's default {sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`]
|
In addition to Spring Boot's predefined {sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`]
|
||||||
types, it is also possible to introduce custom `Status` types to represent more
|
types, it is also possible for `Health` to return a custom `Status` that represents a
|
||||||
complex system states. In such cases a custom implementation of the
|
new system state. In such cases a custom implementation of the
|
||||||
{sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`]
|
{sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`]
|
||||||
interface also needs to be provided, or the default implementation has to be configured
|
interface also needs to be provided, or the default implementation has to be configured
|
||||||
using the `management.health.status.order` configuration property.
|
using the `management.health.status.order` configuration property.
|
||||||
|
@ -277,7 +278,7 @@ Maven '`project properties`' via `@..@` placeholders, e.g.
|
||||||
project.name=Demo
|
project.name=Demo
|
||||||
project.version=X.X.X.X
|
project.version=X.X.X.X
|
||||||
project.description=Demo project for info endpoint
|
project.description=Demo project for info endpoint
|
||||||
info.build.artifact=${project.artifactId}
|
info.build.artifact=@project.artifactId@
|
||||||
info.build.name=@project.name@
|
info.build.name=@project.name@
|
||||||
info.build.description=@project.description@
|
info.build.description=@project.description@
|
||||||
info.build.version=@project.version@
|
info.build.version=@project.version@
|
||||||
|
@ -367,16 +368,17 @@ for Gradle users, although a little more work is required to generate the proper
|
||||||
[[production-ready-monitoring]]
|
[[production-ready-monitoring]]
|
||||||
== Monitoring and management over HTTP
|
== Monitoring and management over HTTP
|
||||||
If you are developing a Spring MVC application, Spring Boot Actuator will auto-configure
|
If you are developing a Spring MVC application, Spring Boot Actuator will auto-configure
|
||||||
all non-sensitive endpoints to be exposed over HTTP. The default convention is to use the
|
all enabled endpoints to be exposed over HTTP. The default convention is to use the
|
||||||
`id` of the endpoint as the URL path. For example, `health` is exposed as `/health`.
|
`id` of the endpoint as the URL path. For example, `health` is exposed as `/health`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[production-ready-sensitive-endpoints]]
|
[[production-ready-sensitive-endpoints]]
|
||||||
=== Exposing sensitive endpoints
|
=== Securing sensitive endpoints
|
||||||
If you use '`Spring Security`' sensitive endpoints will be exposed over HTTP, but also
|
If you add '`Spring Security`' to you project, all sensitive endpoints exposed over HTTP
|
||||||
protected. By default '`basic`' authentication will be used with the username `user`
|
will be protected. By default '`basic`' authentication will be used with the username
|
||||||
and a generated password (which is printed on the console when the application starts).
|
`user` and a generated password (which is printed on the console when the application
|
||||||
|
starts).
|
||||||
|
|
||||||
TIP: Generated passwords are logged as the application starts. Search for '`Using default
|
TIP: Generated passwords are logged as the application starts. Search for '`Using default
|
||||||
security password`'.
|
security password`'.
|
||||||
|
@ -760,6 +762,23 @@ NOTE: In this example we are actually accessing the endpoint over HTTP using the
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[production-ready-system-metrics]]
|
||||||
|
=== System metrics
|
||||||
|
The following system metrics are exposed by Spring Boot:
|
||||||
|
|
||||||
|
* The total system memory in Kb (`mem`)
|
||||||
|
* The amount of free memory in Kb (`mem.free`)
|
||||||
|
* The number of processors (`processors`)
|
||||||
|
* The system uptime in milliseconds (`uptime`)
|
||||||
|
* The application context uptime in milliseconds (`instance.uptime`)
|
||||||
|
* The average system load (`systemload.average`)
|
||||||
|
* Heap information in Kb (`heap`, `heap.committed`, `heap.init`, `heap.used`)
|
||||||
|
* Thread information (`threads`, `thread.peak`, `thead.daemon`)
|
||||||
|
* Class load information (`classes`, `classes.loaded`, `classes.unloaded`)
|
||||||
|
* Garbage collection information (`gc.xxx.count`, `gc.xxx.time`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[production-ready-datasource-metrics]]
|
[[production-ready-datasource-metrics]]
|
||||||
=== DataSource metrics
|
=== DataSource metrics
|
||||||
The following metrics are exposed for each supported `DataSource` defined in your
|
The following metrics are exposed for each supported `DataSource` defined in your
|
||||||
|
@ -788,6 +807,14 @@ beans if your favorite data source isn't supported out of the box. See
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[production-ready-session-metrics]]
|
||||||
|
=== Tomcat session metrics
|
||||||
|
If you are using Tomcat as your embedded servlet container, session metrics will
|
||||||
|
automatically be exposed. The `httpsessions.active` and `httpsessions.max` keys provide
|
||||||
|
the number of active and maximum sessions.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[production-ready-recording-metrics]]
|
[[production-ready-recording-metrics]]
|
||||||
=== Recording your own metrics
|
=== Recording your own metrics
|
||||||
To record your own metrics inject a
|
To record your own metrics inject a
|
||||||
|
@ -857,14 +884,16 @@ an `Exporter` interface and a few basic implementations for you to get started w
|
||||||
|
|
||||||
|
|
||||||
[[production-ready-code-hale-metrics]]
|
[[production-ready-code-hale-metrics]]
|
||||||
=== Coda Hale Metrics
|
=== Dropwizard Metrics
|
||||||
User of the http://metrics.codahale.com/[Coda Hale '`Metrics`' library] will automatically
|
User of the https://dropwizard.github.io/metrics/[Dropwizard '`Metrics`' library] will
|
||||||
find that Spring Boot metrics are published to `com.codahale.metrics.MetricRegistry`. A
|
automatically find that Spring Boot metrics are published to
|
||||||
default `com.codahale.metrics.MetricRegistry` Spring bean will be created when you declare
|
`com.codahale.metrics.MetricRegistry`. A default `com.codahale.metrics.MetricRegistry`
|
||||||
a dependency to the `com.codahale.metrics:metrics-core` library; you can also register you
|
Spring bean will be created when you declare a dependency to the
|
||||||
own `@Bean` instance if you need customizations.
|
`io.dropwizard.metrics:metrics-core` library; you can also register you own `@Bean`
|
||||||
|
instance if you need customizations. Metrics from the `MetricRegistry` are also
|
||||||
|
automatically exposed via the `/metrics` endpoint
|
||||||
|
|
||||||
Users can create Coda Hale metrics by prefixing their metric names with the appropriate
|
Users can create Dropwizard metrics by prefixing their metric names with the appropriate
|
||||||
type (e.g. `+histogram.*+`, `+meter.*+`).
|
type (e.g. `+histogram.*+`, `+meter.*+`).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
[partintro]
|
[partintro]
|
||||||
--
|
--
|
||||||
The Spring Boot CLI is a command line tool that can be used if you want to quickly
|
The Spring Boot CLI is a command line tool that can be used if you want to quickly
|
||||||
prototype with Spring. It allows you to run Groovy scripts, which means that you have a
|
develop with Spring. It allows you to run Groovy scripts, which means that you have a
|
||||||
familiar Java-like syntax, without so much boilerplate code. You can also bootstrap
|
familiar Java-like syntax, without so much boilerplate code. You can also bootstrap
|
||||||
a new project or write your own command for it.
|
a new project or write your own command for it.
|
||||||
--
|
--
|
||||||
|
@ -119,45 +119,11 @@ To set JVM command line arguments you can use the `JAVA_OPTS` environment variab
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-install-uninstall]]
|
|
||||||
=== Adding dependencies to the CLI
|
|
||||||
You can add dependencies to the CLI using the `install` command. The command takes one
|
|
||||||
or more sets of artifact coordinates in the format `group:artifact:version`. For example:
|
|
||||||
|
|
||||||
[indent=0,subs="verbatim,quotes,attributes"]
|
|
||||||
----
|
|
||||||
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
|
|
||||||
----
|
|
||||||
|
|
||||||
In addition to installing the artifacts identified by the coordinates you supply, all of
|
|
||||||
the artifacts' dependencies will also be installed.
|
|
||||||
|
|
||||||
To uninstall a dependency use the `uninstall` command. As with the `install` command, it
|
|
||||||
takes one or more sets of artifact coordinates in the format `group:artifact:version`.
|
|
||||||
For example:
|
|
||||||
|
|
||||||
[indent=0,subs="verbatim,quotes,attributes"]
|
|
||||||
----
|
|
||||||
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
|
|
||||||
----
|
|
||||||
|
|
||||||
It will uninstall the artifacts identified by the coordinates you supply and their
|
|
||||||
dependencies.
|
|
||||||
|
|
||||||
To uninstall all additional dependencies you can use the `--all` option. For example:
|
|
||||||
|
|
||||||
[indent=0,subs="verbatim,quotes,attributes"]
|
|
||||||
----
|
|
||||||
$ spring uninstall --all
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-deduced-grab-annotations]]
|
[[cli-deduced-grab-annotations]]
|
||||||
==== Deduced "`grab`" dependencies
|
==== Deduced "`grab`" dependencies
|
||||||
Standard Groovy includes a `@Grab` annotation which allows you to declare dependencies
|
Standard Groovy includes a `@Grab` annotation which allows you to declare dependencies
|
||||||
on a third-party libraries. This useful technique allows Groovy to download jars in the
|
on a third-party libraries. This useful technique allows Groovy to download jars in the
|
||||||
same way as Maven or Gradle would; but without requiring you to use a build tool.
|
same way as Maven or Gradle would, but without requiring you to use a build tool.
|
||||||
|
|
||||||
Spring Boot extends this technique further, and will attempt to deduce which libraries
|
Spring Boot extends this technique further, and will attempt to deduce which libraries
|
||||||
to "`grab`" based on your code. For example, since the `WebApplication` code above uses
|
to "`grab`" based on your code. For example, since the `WebApplication` code above uses
|
||||||
|
@ -226,24 +192,6 @@ metadata can be found in the <<appendix-dependency-versions, appendix>>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-default-grab-deduced-coordinates-custom-metadata]]
|
|
||||||
===== Custom "`grab`" metadata
|
|
||||||
Spring Boot provides a new annotation, `@GrabMetadata` that can be used to provide custom
|
|
||||||
dependency metadata that overrides Spring Boot's defaults. This metadata is specified by
|
|
||||||
using this annotation to provide the coordinates of one or more properties files (deployed
|
|
||||||
to a Maven repository with a "type" identifier: "properties"). For example
|
|
||||||
`@GrabMetadata(['com.example:versions-one:1.0.0', 'com.example.versions-two:1.0.0'])` will
|
|
||||||
pick up files in a Maven repository in "com/example/versions-*/1.0.0/versions-*-1.0.0.properties". The
|
|
||||||
properties files are applied in the order that they're specified. In the example above, this
|
|
||||||
means that properties in `versions-two` will override properties in `versions-one`. Each entry
|
|
||||||
in each properties file must be in the form `group:module=version`. You can use `@GrabMetadata`
|
|
||||||
anywhere that you can use `@Grab`, however, to ensure consistent ordering of the metadata, you
|
|
||||||
can only use `@GrabMetadata` at most once in your application. A useful source of dependency
|
|
||||||
metadata (a superset of Spring Boot) is the http://platform.spring.io/[Spring IO Platform], e.g.
|
|
||||||
`@GrabMetadata('io.spring.platform:platform-versions:1.0.0.RELEASE')`.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-default-import-statements]]
|
[[cli-default-import-statements]]
|
||||||
==== Default import statements
|
==== Default import statements
|
||||||
To help reduce the size of your Groovy code, several `import` statements are
|
To help reduce the size of your Groovy code, several `import` statements are
|
||||||
|
@ -265,6 +213,43 @@ Unlike the equivalent Java application, you do not need to include a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[cli-default-grab-deduced-coordinates-custom-metadata]]
|
||||||
|
==== Custom "`grab`" metadata
|
||||||
|
Spring Boot provides a new `@GrabMetadata` annotation that can be used to provide custom
|
||||||
|
dependency metadata that overrides Spring Boot's defaults. This metadata is specified by
|
||||||
|
using the annotation to provide coordinates of one or more properties files (deployed
|
||||||
|
to a Maven repository with a "`type`" identifier of `properties`). Each entry in each
|
||||||
|
properties file must be in the form `group:module=version`.
|
||||||
|
|
||||||
|
For example, the following declaration:
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
`@GrabMetadata("com.example.custom-versions:1.0.0")`
|
||||||
|
----
|
||||||
|
|
||||||
|
Will pick up `custom-versions-1.0.0.properties` in a Maven repository under
|
||||||
|
`com/example/custom-versions/1.0.0/`.
|
||||||
|
|
||||||
|
Multiple properties files can be specified from the annotation, they will be applied in
|
||||||
|
the order that they're declared. For example:
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
`@GrabMetadata(["com.example.custom-versions:1.0.0",
|
||||||
|
"com.example.more-versions:1.0.0"])`
|
||||||
|
----
|
||||||
|
|
||||||
|
indicates that properties in `more-versions` will override properties in `custom-versions`.
|
||||||
|
|
||||||
|
You can use `@GrabMetadata` anywhere that you can use `@Grab`, however, to ensure
|
||||||
|
consistent ordering of the metadata, you can only use `@GrabMetadata` at most once in your
|
||||||
|
application. A useful source of dependency metadata (a superset of Spring Boot) is the
|
||||||
|
http://platform.spring.io/[Spring IO Platform], e.g.
|
||||||
|
`@GrabMetadata('io.spring.platform:platform-versions:1.0.4.RELEASE')`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-testing]]
|
[[cli-testing]]
|
||||||
=== Testing your code
|
=== Testing your code
|
||||||
The `test` command allows you to compile and run tests for your application. Typical
|
The `test` command allows you to compile and run tests for your application. Typical
|
||||||
|
@ -360,7 +345,7 @@ without leaving the shell. For example:
|
||||||
|
|
||||||
[indent=0]
|
[indent=0]
|
||||||
----
|
----
|
||||||
$ spring init --dependencies=web,data-jpa my-project/
|
$ spring init --dependencies=web,data-jpa my-project
|
||||||
Using service at https://start.spring.io
|
Using service at https://start.spring.io
|
||||||
Project extracted to '/Users/developer/example/my-project'
|
Project extracted to '/Users/developer/example/my-project'
|
||||||
----
|
----
|
||||||
|
@ -433,6 +418,40 @@ embedded shell.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[cli-install-uninstall]]
|
||||||
|
=== Adding extensions to the CLI
|
||||||
|
You can add extensions to the CLI using the `install` command. The command takes one
|
||||||
|
or more sets of artifact coordinates in the format `group:artifact:version`. For example:
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
|
----
|
||||||
|
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
|
||||||
|
----
|
||||||
|
|
||||||
|
In addition to installing the artifacts identified by the coordinates you supply, all of
|
||||||
|
the artifacts' dependencies will also be installed.
|
||||||
|
|
||||||
|
To uninstall a dependency use the `uninstall` command. As with the `install` command, it
|
||||||
|
takes one or more sets of artifact coordinates in the format `group:artifact:version`.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
|
----
|
||||||
|
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
|
||||||
|
----
|
||||||
|
|
||||||
|
It will uninstall the artifacts identified by the coordinates you supply and their
|
||||||
|
dependencies.
|
||||||
|
|
||||||
|
To uninstall all additional dependencies you can use the `--all` option. For example:
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
|
----
|
||||||
|
$ spring uninstall --all
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-groovy-beans-dsl]]
|
[[cli-groovy-beans-dsl]]
|
||||||
== Developing application with the Groovy beans DSL
|
== Developing application with the Groovy beans DSL
|
||||||
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from
|
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from
|
||||||
|
|
|
@ -386,9 +386,9 @@ NOTE: If you use '`starter POMs`' SnakeYAML will be automatically provided via
|
||||||
|
|
||||||
[[boot-features-external-config-loading-yaml]]
|
[[boot-features-external-config-loading-yaml]]
|
||||||
==== Loading YAML
|
==== Loading YAML
|
||||||
Spring Boot provides two convenient classes that can be used to load YAML documents. The
|
Spring Framework provides two convenient classes that can be used to load YAML documents.
|
||||||
`YamlPropertiesFactoryBean` will load YAML as `Properties` and the `YamlMapFactoryBean`
|
The `YamlPropertiesFactoryBean` will load YAML as `Properties` and the
|
||||||
will load YAML as a `Map`.
|
`YamlMapFactoryBean` will load YAML as a `Map`.
|
||||||
|
|
||||||
For example, the following YAML document:
|
For example, the following YAML document:
|
||||||
|
|
||||||
|
@ -441,6 +441,7 @@ with a mutable value, e.g. this will bind to the properties above
|
||||||
----
|
----
|
||||||
@ConfigurationProperties(prefix="my")
|
@ConfigurationProperties(prefix="my")
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
private List<String> servers = new ArrayList<String>();
|
private List<String> servers = new ArrayList<String>();
|
||||||
|
|
||||||
public List<String> getServers() {
|
public List<String> getServers() {
|
||||||
|
@ -566,6 +567,9 @@ definitions by simply listing the properties classes directly in the
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
TIP: Using `@ConfigurationProperties` also allows you to generate meta-data files that can
|
||||||
|
be used by IDEs. See the <<configuration-metadata>> appendix for details.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[boot-features-external-config-relaxed-binding]]
|
[[boot-features-external-config-relaxed-binding]]
|
||||||
|
@ -1103,7 +1107,7 @@ If you prefer the JAX-RS programming model for REST endpoints you can use one of
|
||||||
available implementations instead of Spring MVC. Jersey 1.x and Apache Celtix work
|
available implementations instead of Spring MVC. Jersey 1.x and Apache Celtix work
|
||||||
quite well out of the box if you just register their `Servlet` or `Filter` as a
|
quite well out of the box if you just register their `Servlet` or `Filter` as a
|
||||||
`@Bean` in your application context. Jersey 2.x has some native Spring support so
|
`@Bean` in your application context. Jersey 2.x has some native Spring support so
|
||||||
we also provide autoconfiguration support for it in Spring Boot together with a
|
we also provide auto-configuration support for it in Spring Boot together with a
|
||||||
starter.
|
starter.
|
||||||
|
|
||||||
To get started with Jersey 2.x just include the `spring-boot-starter-jersey` as a
|
To get started with Jersey 2.x just include the `spring-boot-starter-jersey` as a
|
||||||
|
@ -1114,9 +1118,11 @@ all the endpoints:
|
||||||
----
|
----
|
||||||
@Component
|
@Component
|
||||||
public class JerseyConfig extends ResourceConfig {
|
public class JerseyConfig extends ResourceConfig {
|
||||||
|
|
||||||
public JerseyConfig() {
|
public JerseyConfig() {
|
||||||
register(Endpoint.class);
|
register(Endpoint.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -1139,14 +1145,14 @@ All the registered endpoints should be `@Components` with HTTP resource annotati
|
||||||
|
|
||||||
Since the `Endpoint` is a Spring `@Component` its lifecycle is managed by Spring and you
|
Since the `Endpoint` is a Spring `@Component` its lifecycle is managed by Spring and you
|
||||||
can `@Autowired` dependencies and inject external configuration with `@Value`. The Jersey
|
can `@Autowired` dependencies and inject external configuration with `@Value`. The Jersey
|
||||||
servlet will be registered and mapped to '`+/*+`' by default. You can change the mapping
|
servlet will be registered and mapped to `/*` by default. You can change the mapping
|
||||||
by adding `@ApplicationPath` to your `ResourceConfig`.
|
by adding `@ApplicationPath` to your `ResourceConfig`.
|
||||||
|
|
||||||
By default Jersey will be set up as a Servlet in a `@Bean` of type
|
By default Jersey will be set up as a Servlet in a `@Bean` of type
|
||||||
`ServletRegistrationBean` named "jerseyServletRegistration". You can disable or override
|
`ServletRegistrationBean` named `jerseyServletRegistration`. You can disable or override
|
||||||
that bean by creating one of your own with the same name. You can also use a Filter
|
that bean by creating one of your own with the same name. You can also use a Filter
|
||||||
instead of a Servlet by setting `spring.jersey.type=filter` (in which case the `@Bean` to
|
instead of a Servlet by setting `spring.jersey.type=filter` (in which case the `@Bean` to
|
||||||
replace or override is "jerseyFilterRegistration"). The servlet has an `@Order` which you
|
replace or override is `jerseyFilterRegistration`). The servlet has an `@Order` which you
|
||||||
can set with `spring.jersey.filter.order`. Both the Servlet and the Filter registrations
|
can set with `spring.jersey.filter.order`. Both the Servlet and the Filter registrations
|
||||||
can be given init parameters using `spring.jersey.init.*` to specify a map of properties.
|
can be given init parameters using `spring.jersey.init.*` to specify a map of properties.
|
||||||
|
|
||||||
|
@ -1277,7 +1283,7 @@ packaged as an executable archive), there are some limitations in the JSP suppor
|
||||||
|
|
||||||
* Jetty does not currently work as an embedded container with JSPs.
|
* Jetty does not currently work as an embedded container with JSPs.
|
||||||
|
|
||||||
* Undertow does not support JSPs
|
* Undertow does not support JSPs.
|
||||||
|
|
||||||
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
|
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
|
||||||
you can see how to set things up.
|
you can see how to set things up.
|
||||||
|
@ -1710,26 +1716,32 @@ several conveniences for working with MongoDB, including the The
|
||||||
|
|
||||||
[[boot-features-connecting-to-mongodb]]
|
[[boot-features-connecting-to-mongodb]]
|
||||||
==== Connecting to a MongoDB database
|
==== Connecting to a MongoDB database
|
||||||
You can inject an auto-configured `com.mongodb.Mongo` instance as you would any other
|
You can inject an auto-configured `org.springframework.data.mongodb.MongoDbFactory` to
|
||||||
Spring Bean. By default the instance will attempt to connect to a MongoDB server using
|
access Mono databases. By default the instance will attempt to connect to a MongoDB server
|
||||||
the URL `mongodb://localhost/test`:
|
using the URL `mongodb://localhost/test`:
|
||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
import com.mongodb.Mongo;
|
import org.springframework.data.mongodb.MongoDbFactory;
|
||||||
|
import import com.mongodb.DB;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class MyBean {
|
public class MyBean {
|
||||||
|
|
||||||
private final Mongo mongo;
|
private final MongoDbFactory mongo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MyBean(Mongo mongo) {
|
public MyBean(MongoDbFactory mongo) {
|
||||||
this.mongo = mongo;
|
this.mongo = mongo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
public void example() {
|
||||||
|
DB db = mongo.getDb();
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -1746,8 +1758,11 @@ specify a `host`/`port`. For example, you might declare the following in your
|
||||||
TIP: If `spring.data.mongodb.port` is not specified the default of `27017` is used. You
|
TIP: If `spring.data.mongodb.port` is not specified the default of `27017` is used. You
|
||||||
could simply delete this line from the sample above.
|
could simply delete this line from the sample above.
|
||||||
|
|
||||||
You can also declare your own `Mongo` `@Bean` if you want to take complete control of
|
TIP: If you aren't using Spring Data Mongo you can inject `com.mongodb.Mongo` beans
|
||||||
establishing the MongoDB connection.
|
instead of using `MongoDbFactory`.
|
||||||
|
|
||||||
|
You can also declare your own `MongoDbFactory` or `Mongo` `@Beans` if you want to take
|
||||||
|
complete control of establishing the MongoDB connection.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1943,7 +1958,7 @@ receive messages asynchronously. Spring AMQP provides a similar feature set for
|
||||||
'`Advanced Message Queuing Protocol`' and Boot also provides auto-configuration options
|
'`Advanced Message Queuing Protocol`' and Boot also provides auto-configuration options
|
||||||
for `RabbitTemplate` and RabbitMQ. There is also support for STOMP messaging natively
|
for `RabbitTemplate` and RabbitMQ. There is also support for STOMP messaging natively
|
||||||
in Spring Websocket and Spring Boot has support for that through starters and a small
|
in Spring Websocket and Spring Boot has support for that through starters and a small
|
||||||
amount of auto configuration.
|
amount of auto-configuration.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2088,7 +2103,9 @@ The following component creates a listener endpoint on the `someQueue` destinati
|
||||||
public class MyBean {
|
public class MyBean {
|
||||||
|
|
||||||
@JmsListener(destination = "someQueue")
|
@JmsListener(destination = "someQueue")
|
||||||
public void processMessage(String content) { ... }
|
public void processMessage(String content) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
@ -2598,6 +2615,16 @@ care must be taken not to refer to bean definitions that have not yet been creat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[boot-features-property-conditions]]
|
||||||
|
==== Property conditions
|
||||||
|
The `@ConditionalOnProperty` annotation allows configuration to be included based on a
|
||||||
|
Spring Environment property. Use the `prefix` and `name` attributes to specify the
|
||||||
|
property that should be checked. By default any property that exists and is not equal to
|
||||||
|
`false` will be matched. You can also create more advanced checks using the `havingValue`
|
||||||
|
and `matchIfMissing` attributes.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[boot-features-resource-conditions]]
|
[[boot-features-resource-conditions]]
|
||||||
==== Resource conditions
|
==== Resource conditions
|
||||||
The `@ConditionalOnResource` annotation allows configuration to be included only when a
|
The `@ConditionalOnResource` annotation allows configuration to be included only when a
|
||||||
|
@ -2624,8 +2651,8 @@ result of a {spring-reference}/#expressions[SpEL expression].
|
||||||
|
|
||||||
[[boot-features-websockets]]
|
[[boot-features-websockets]]
|
||||||
== WebSockets
|
== WebSockets
|
||||||
Spring Boot provides WebSockets auto-configuration for embedded Tomcat (7 and 8) and
|
Spring Boot provides WebSockets auto-configuration for embedded Tomcat (8 and 7), Jetty 9
|
||||||
embedded Jetty 9. If you're deploying a war file to a standalone container, Spring Boot
|
and Undertow. If you're deploying a war file to a standalone container, Spring Boot
|
||||||
assumes that the container will be responsible for the configuration of its WebSocket
|
assumes that the container will be responsible for the configuration of its WebSocket
|
||||||
support.
|
support.
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,10 @@ The following application starters are provided by Spring Boot under the
|
||||||
|`spring-boot-starter-batch`
|
|`spring-boot-starter-batch`
|
||||||
|Support for "`Spring Batch`" including HSQLDB database.
|
|Support for "`Spring Batch`" including HSQLDB database.
|
||||||
|
|
||||||
|
|`spring-boot-starter-cloud-connectors`
|
||||||
|
|Support for "`Spring Cloud Connectors`" which simplifies connecting to services in cloud
|
||||||
|
platforms like Cloud Foundry and Heroku.
|
||||||
|
|
||||||
|`spring-boot-starter-data-elasticsearch`
|
|`spring-boot-starter-data-elasticsearch`
|
||||||
|Support for the Elasticsearch search and analytics engine including
|
|Support for the Elasticsearch search and analytics engine including
|
||||||
`spring-data-elasticsearch`.
|
`spring-data-elasticsearch`.
|
||||||
|
@ -269,21 +273,24 @@ and Hibernate.
|
||||||
|`spring-boot-starter-jdbc`
|
|`spring-boot-starter-jdbc`
|
||||||
|Support for JDBC databases.
|
|Support for JDBC databases.
|
||||||
|
|
||||||
|
|`spring-boot-starter-jersey`
|
||||||
|
|Support for the Jersey RESTful Web Services framework.
|
||||||
|
|
||||||
|`spring-boot-starter-jta-atomikos`
|
|`spring-boot-starter-jta-atomikos`
|
||||||
|Support for JTA distributed transactions via Atomikos.
|
|Support for JTA distributed transactions via Atomikos.
|
||||||
|
|
||||||
|`spring-boot-starter-jta-bitronix`
|
|`spring-boot-starter-jta-bitronix`
|
||||||
|Support for JTA distributed transactions via Bitronix.
|
|Support for JTA distributed transactions via Bitronix.
|
||||||
|
|
||||||
|
|`spring-boot-starter-mail`
|
||||||
|
|Support for `javax.mail`.
|
||||||
|
|
||||||
|`spring-boot-starter-mobile`
|
|`spring-boot-starter-mobile`
|
||||||
|Support for `spring-mobile`
|
|Support for `spring-mobile`
|
||||||
|
|
||||||
|`spring-boot-starter-redis`
|
|`spring-boot-starter-redis`
|
||||||
|Support for the REDIS key-value data store, including `spring-redis`.
|
|Support for the REDIS key-value data store, including `spring-redis`.
|
||||||
|
|
||||||
|`spring-boot-starter-remote-shell`
|
|
||||||
|Support for `CRaSH`.
|
|
||||||
|
|
||||||
|`spring-boot-starter-security`
|
|`spring-boot-starter-security`
|
||||||
|Support for `spring-security`.
|
|Support for `spring-security`.
|
||||||
|
|
||||||
|
@ -371,8 +378,8 @@ best practices that help.
|
||||||
When a class doesn't include a `package` declaration it is considered to be in the
|
When a class doesn't 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 `@ComponentScan` or `@EntityScan` annotations, since every class from every jar,
|
use `@ComponentScan`, `@EntityScan` or `@SpringBootApplication` annotations, since every
|
||||||
will be read.
|
class from every jar, will be read.
|
||||||
|
|
||||||
TIP: We recommend that you follow Java's recommended package naming conventions
|
TIP: We recommend that you follow Java's recommended package naming conventions
|
||||||
and use a reversed domain name (for example, `com.example.project`).
|
and use a reversed domain name (for example, `com.example.project`).
|
||||||
|
@ -388,7 +395,8 @@ example, if you are writing a JPA application, the package of the
|
||||||
`@EnableAutoConfiguration` annotated class will be used to search for `@Entity` items.
|
`@EnableAutoConfiguration` annotated class will be used to search for `@Entity` items.
|
||||||
|
|
||||||
Using a root package also allows the `@ComponentScan` annotation to be used without
|
Using a root package also allows the `@ComponentScan` annotation to be used without
|
||||||
needing to specify a `basePackage` attribute.
|
needing to specify a `basePackage` attribute. You can also use the
|
||||||
|
`@SpringBootApplication` annotation if your main class is in the root package.
|
||||||
|
|
||||||
Here is a typical layout:
|
Here is a typical layout:
|
||||||
|
|
||||||
|
@ -473,8 +481,8 @@ 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
|
`HSQLDB` is on your classpath, and you have not manually configured any database
|
||||||
connection beans, then we will auto-configure an in-memory database.
|
connection beans, then we will auto-configure an in-memory database.
|
||||||
|
|
||||||
You need to opt-in to auto-configuration by adding the `@EnableAutoConfiguration`
|
You need to opt-in to auto-configuration by adding the `@EnableAutoConfiguration` or
|
||||||
annotation to one of your `@Configuration` classes.
|
`@SpringBootApplication` annotations to one of your `@Configuration` classes.
|
||||||
|
|
||||||
TIP: You should only ever add one `@EnableAutoConfiguration` annotation. We generally
|
TIP: You should only ever add one `@EnableAutoConfiguration` annotation. We generally
|
||||||
recommend that you add it to your primary `@Configuration` class.
|
recommend that you add it to your primary `@Configuration` class.
|
||||||
|
@ -645,7 +653,7 @@ resources for instant "`hot`" reload.
|
||||||
$ mvn spring-boot:run
|
$ mvn spring-boot:run
|
||||||
----
|
----
|
||||||
|
|
||||||
Useful operating system environment variable:
|
You might also want to use the useful operating system environment variable:
|
||||||
|
|
||||||
[indent=0,subs="attributes"]
|
[indent=0,subs="attributes"]
|
||||||
----
|
----
|
||||||
|
@ -668,7 +676,7 @@ the `spring-boot-plugin`
|
||||||
$ gradle bootRun
|
$ gradle bootRun
|
||||||
----
|
----
|
||||||
|
|
||||||
Useful operating system environment variable:
|
You might also want to use this useful operating system environment variable:
|
||||||
|
|
||||||
[indent=0,subs="attributes"]
|
[indent=0,subs="attributes"]
|
||||||
----
|
----
|
||||||
|
|
Loading…
Reference in New Issue