Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b82e2200
Commit
b82e2200
authored
Mar 17, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish spring-boot-features
Wrap at 90 chars more consistently
parent
a4be4670
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
167 deletions
+172
-167
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+172
-167
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
b82e2200
...
@@ -116,6 +116,7 @@ The `SpringApplicationBuilder` allows you to chain together multiple method call
...
@@ -116,6 +116,7 @@ The `SpringApplicationBuilder` allows you to chain together multiple method call
includes `parent` and `child` methods that allow you to create a hierarchy.
includes `parent` and `child` methods that allow you to create a hierarchy.
For example:
For example:
[source,java,indent=0]
[source,java,indent=0]
----
----
new SpringApplicationBuilder()
new SpringApplicationBuilder()
...
@@ -128,8 +129,8 @@ For example:
...
@@ -128,8 +129,8 @@ For example:
NOTE: There are some restrictions when creating an `ApplicationContext` hierarchy, e.g.
NOTE: There are some restrictions when creating an `ApplicationContext` hierarchy, e.g.
Web components *must* be contained within the child context, and the same `Environment`
Web components *must* be contained within the child context, and the same `Environment`
will be used for both parent and child contexts. See the
will be used for both parent and child contexts. See the
{dc-spring-boot}/builder/SpringApplicationBuilder.{dc-ext}[`SpringApplicationBuilder`
Javadoc]
{dc-spring-boot}/builder/SpringApplicationBuilder.{dc-ext}[`SpringApplicationBuilder`
for full details.
Javadoc]
for full details.
...
@@ -172,15 +173,15 @@ you need to override the default.
...
@@ -172,15 +173,15 @@ you need to override the default.
It is also possible to take complete control of the `ApplicationContext` type that will
It is also possible to take complete control of the `ApplicationContext` type that will
be used by calling `setApplicationContextClass(...)`.
be used by calling `setApplicationContextClass(...)`.
TIP: It is often desirable to call `setWebEnvironment(false)` when using
`SpringApplication`
TIP: It is often desirable to call `setWebEnvironment(false)` when using
within a JUnit test.
`SpringApplication`
within a JUnit test.
[[boot-features-command-line-runner]]
[[boot-features-command-line-runner]]
=== Using the CommandLineRunner
=== Using the CommandLineRunner
If you want access to the raw command line arguments, or you need to run some specific
code
If you want access to the raw command line arguments, or you need to run some specific
once the `SpringApplication` has started you can implement the `CommandLineRunner`
code
once the `SpringApplication` has started you can implement the `CommandLineRunner`
interface. The `run(String... args)` method will be called on all Spring beans
interface. The `run(String... args)` method will be called on all Spring beans
implementing this interface.
implementing this interface.
...
@@ -530,20 +531,19 @@ the configuration of your application. For example:
...
@@ -530,20 +531,19 @@ the configuration of your application. For example:
----
----
NOTE: The getters and setters are advisable, since binding is via standard Java Beans
NOTE: The getters and setters are advisable, since binding is via standard Java Beans
property descriptors, just like in Spring MVC. They are mandatory for immutable types
property descriptors, just like in Spring MVC. They are mandatory for immutable types or
or those that are directly coercible from `String`. As long as they are initialized,
those that are directly coercible from `String`. As long as they are initialized, maps,
maps, collections, and arrays need a getter but not necessarily a setter since they
collections, and arrays need a getter but not necessarily a setter since they can be
can be mutated by the binder. If there is a setter, Maps, collections, and arrays can
mutated by the binder. If there is a setter, Maps, collections, and arrays can be created.
be created. Maps and collections can be expanded with only a getter, whereas arrays
Maps and collections can be expanded with only a getter, whereas arrays require a setter.
require a setter. Nested POJO properties can also be created (so a setter is not
Nested POJO properties can also be created (so a setter is not mandatory) if they have a
mandatory) if they have a default constructor, or a constructor accepting a single
default constructor, or a constructor accepting a single value that can be coerced from
value that can be coerced from String. Some people use Project Lombok to add getters
String. Some people use Project Lombok to add getters and setters automatically.
and setters automatically.
When the `@EnableConfigurationProperties` annotation is applied to your `@Configuration`,
When the `@EnableConfigurationProperties` annotation is applied to your `@Configuration`,
any beans annotated with `@ConfigurationProperties` will be automatically configured
any beans annotated with `@ConfigurationProperties` will be automatically configured
from
from the `Environment` properties. This style of configuration works particularly well
the `Environment` properties. This style of configuration works particularly well with the
with the
`SpringApplication` external YAML configuration:
`SpringApplication` external YAML configuration:
[source,yaml,indent=0]
[source,yaml,indent=0]
----
----
...
@@ -860,8 +860,8 @@ current directory.
...
@@ -860,8 +860,8 @@ current directory.
|_(none)_
|_(none)_
|Specific directory
|Specific directory
|`/var/log`
|`/var/log`
|Writes `spring.log` t
he specified directory. Names can be an exact location or relative to the
|Writes `spring.log` t
o the specified directory. Names can be an exact location or
current directory.
relative to the
current directory.
|===
|===
Log files will rotate when they reach 10 Mb and as with console output, `ERROR`, `WARN`
Log files will rotate when they reach 10 Mb and as with console output, `ERROR`, `WARN`
...
@@ -872,9 +872,9 @@ and `INFO` level messages are logged by default.
...
@@ -872,9 +872,9 @@ and `INFO` level messages are logged by default.
[[boot-features-custom-log-levels]]
[[boot-features-custom-log-levels]]
=== Log Levels
=== Log Levels
All the supported logging systems can have the logger levels set in the Spring
All the supported logging systems can have the logger levels set in the Spring
`Environment` (so for example in `application.properties`) using
'`+logging.level.*=LEVEL+`'
`Environment` (so for example in `application.properties`) using
where '`LEVEL`' is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. Example
'`+logging.level.*=LEVEL+`' where '`LEVEL`' is one of TRACE, DEBUG, INFO, WARN, ERROR,
`application.properties`:
FATAL, OFF. Example
`application.properties`:
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
----
----
...
@@ -1030,6 +1030,7 @@ default.
...
@@ -1030,6 +1030,7 @@ default.
If you need to add or customize converters you can use Spring Boot's
If you need to add or customize converters you can use Spring Boot's
`HttpMessageConverters` class:
`HttpMessageConverters` class:
[source,java,indent=0]
[source,java,indent=0]
----
----
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
...
@@ -1077,9 +1078,9 @@ Spring decides not to handle it. Most of the time this will not happen (unless y
...
@@ -1077,9 +1078,9 @@ Spring decides not to handle it. Most of the time this will not happen (unless y
the default MVC configuration) because Spring will always be able to handle requests
the default MVC configuration) because Spring will always be able to handle requests
through the `DispatcherServlet`.
through the `DispatcherServlet`.
In addition to the '`standard`' static resource locations above, a special case is made
for
In addition to the '`standard`' static resource locations above, a special case is made
http://www.webjars.org/[Webjars content]. Any resources with a path in `+/webjars/**+` will
for http://www.webjars.org/[Webjars content]. Any resources with a path in `+/webjars/**+`
be served from jar files if they are packaged in the Webjars format.
will
be served from jar files if they are packaged in the Webjars format.
TIP: Do not use the `src/main/webapp` directory if your application will be packaged as a
TIP: Do not use the `src/main/webapp` directory if your application will be packaged as a
jar. Although this directory is a common standard, it will *only* work with war packaging
jar. Although this directory is a common standard, it will *only* work with war packaging
...
@@ -1112,22 +1113,22 @@ TIP: IntelliJ IDEA orders the classpath differently depending on how you run you
...
@@ -1112,22 +1113,22 @@ TIP: IntelliJ IDEA orders the classpath differently depending on how you run you
application. Running your application in the IDE via its main method will result in a
application. Running your application in the IDE via its main method will result in a
different ordering to when you run your application using Maven or Gradle or from its
different ordering to when you run your application using Maven or Gradle or from its
pacakaged jar. This can cause Spring Boot to fail to find the templates on the classpath.
pacakaged jar. This can cause Spring Boot to fail to find the templates on the classpath.
If you're affected by this problem you can reorder the classpath in the IDE to place
If you're affected by this problem you can reorder the classpath in the IDE to place
the
the module's classes and resources first. Alternatively, you can configure the template
module's classes and resources first. Alternatively, you can configure the template prefix
prefix
to search every templates directory on the classpath: `classpath*:/templates/`.
to search every templates directory on the classpath: `classpath*:/templates/`.
[[boot-features-error-handling]]
[[boot-features-error-handling]]
==== Error Handling
==== Error Handling
Spring Boot provides an `/error` mapping by default that handles all errors in a
Spring Boot provides an `/error` mapping by default that handles all errors in a
sensible
sensible way, and it is registered as a '`global`' error page in the servlet container.
way, and it is registered as a '`global`' error page in the servlet container. For machine
For machine clients it will produce a JSON response with details of the error, the HTTP
clients it will produce a JSON response with details of the error, the HTTP status and the
status and the exception message. For browser clients there is a '`whitelabel`' error
exception message. For browser clients there is a '`whitelabel`' error view that renders
view that renders the same data in HTML format (to customize it just add a `View` that
the same data in HTML format (to customize it just add a `View` that resolves to
resolves to
'`error`'). To replace the default behaviour completely you can implement
'`error`'). To replace the default behaviour completely you can implement
`ErrorController` and register a bean definition of that type, or simply add a bean
`ErrorController` and register a bean definition of that type, or simply add a bean
of
of
type `ErrorAttributes` to use the existing mechanism but replace the contents.
type `ErrorAttributes` to use the existing mechanism but replace the contents.
If you want more specific error pages for some conditions, the embedded servlet containers
If you want more specific error pages for some conditions, the embedded servlet containers
support a uniform Java DSL for customizing the error handling. For example:
support a uniform Java DSL for customizing the error handling. For example:
...
@@ -1174,14 +1175,16 @@ then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, e.g.
...
@@ -1174,14 +1175,16 @@ then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, e.g.
(the default `FilterRegistrationBean` does not include the `ERROR` dispatcher type).
(the default `FilterRegistrationBean` does not include the `ERROR` dispatcher type).
[[boot-features-error-handling-websphere]]
[[boot-features-error-handling-websphere]]
===== Error Handling on WebSphere Application Server
===== Error Handling on WebSphere Application Server
When deployed to a servlet container, a Spring Boot uses its error page filter to
When deployed to a servlet container, a Spring Boot uses its error page filter to
forward
forward a request with an error status to the appropriate error page. The request can
a request with an error status to the appropriate error page. The request can only be
only be forwarded to the correct error page if the response has not already been
forwarded to the correct error page if the response has not already been committed. By
committed. By default, WebSphere Application Server 8.0 and later commits the response
default, WebSphere Application Server 8.0 and later commits the response upon successful
upon successful completion of a servlet's service method. You should disable this
completion of a servlet's service method. You should disable this behaviour by setting
behaviour by setting
`com.ibm.ws.webcontainer.invokeFlushAfterService` to `false`
`com.ibm.ws.webcontainer.invokeFlushAfterService` to `false`
...
@@ -1191,8 +1194,8 @@ If you're developing a RESTful API that makes use of hypermedia, Spring Boot pro
...
@@ -1191,8 +1194,8 @@ If you're developing a RESTful API that makes use of hypermedia, Spring Boot pro
auto-configuration for Spring HATEOAS that works well with most applications. The
auto-configuration for Spring HATEOAS that works well with most applications. The
auto-configuration replaces the need to use `@EnableHypermediaSupport` and registers a
auto-configuration replaces the need to use `@EnableHypermediaSupport` and registers a
number of beans to ease building hypermedia-based applications including a
number of beans to ease building hypermedia-based applications including a
`LinkDiscoverer` and an `ObjectMapper` configured to correctly marshal responses into
`LinkDiscoverer` and an `ObjectMapper` configured to correctly marshal responses into
the
the
desired representation. The `ObjectMapper` will be customized based on the
desired representation. The `ObjectMapper` will be customized based on the
`spring.jackson.*` properties or a `Jackson2ObjectMapperBuilder` bean if one exists.
`spring.jackson.*` properties or a `Jackson2ObjectMapperBuilder` bean if one exists.
You can take control of Spring HATEOAS's configuration by using
You can take control of Spring HATEOAS's configuration by using
...
@@ -1204,11 +1207,10 @@ described above.
...
@@ -1204,11 +1207,10 @@ described above.
[[boot-features-jersey]]
[[boot-features-jersey]]
=== JAX-RS and Jersey
=== JAX-RS and Jersey
If you prefer the JAX-RS programming model for REST endpoints you can use one of the
If you prefer the JAX-RS programming model for REST endpoints you can use one of the
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
quite well out of the box if you just register their `Servlet` or `Filter` as a
well out of the box if you just register their `Servlet` or `Filter` as a `@Bean` in your
`@Bean` in your application context. Jersey 2.x has some native Spring support so
application context. Jersey 2.x has some native Spring support so we also provide
we also provide auto-configuration support for it in Spring Boot together with a
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
dependency and then you need one `@Bean` of type `ResourceConfig` in which you register
dependency and then you need one `@Bean` of type `ResourceConfig` in which you register
...
@@ -1257,11 +1259,12 @@ can set with `spring.jersey.filter.order`. Both the Servlet and the Filter regis
...
@@ -1257,11 +1259,12 @@ can set with `spring.jersey.filter.order`. Both the Servlet and the Filter regis
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.
There is a {github-code}/spring-boot-samples/spring-boot-sample-jersey[Jersey sample] so
There is a {github-code}/spring-boot-samples/spring-boot-sample-jersey[Jersey sample] so
you can see how to set things up. There is also a {github-code}/spring-boot-samples/spring-boot-sample-jersey1[Jersey 1.x sample].
you can see how to set things up. There is also a
Note that in the Jersey 1.x sample that the spring-boot maven plugin has been configured to
{github-code}/spring-boot-samples/spring-boot-sample-jersey1[Jersey 1.x sample]. Note that
unpack some Jersey jars so they can be scanned by the JAX-RS implementation (because the sample
in the Jersey 1.x sample that the spring-boot maven plugin has been configured to unpack
asks for them to be scanned in its `Filter` registration). You may need to do the same
some Jersey jars so they can be scanned by the JAX-RS implementation (because the sample
if any of your JAX-RS resources are packages as nested jars.
asks for them to be scanned in its `Filter` registration). You may need to do the same if
any of your JAX-RS resources are packages as nested jars.
...
@@ -1280,9 +1283,9 @@ listeners from the Servlet spec (e.g. `HttpSessionListener`) directly as
...
@@ -1280,9 +1283,9 @@ listeners from the Servlet spec (e.g. `HttpSessionListener`) directly as
Spring beans. This can be particularly convenient if you want to refer to a value from
Spring beans. This can be particularly convenient if you want to refer to a value from
your `application.properties` during configuration.
your `application.properties` during configuration.
By default, if the context contains only a single Servlet it will be mapped to `/`. In
By default, if the context contains only a single Servlet it will be mapped to `/`. In
the
the case of multiple Servlet beans the bean name will be used as a path prefix. Filters
case of multiple Servlet beans the bean name will be used as a path prefix. Filters will
will
map to `+/*+`.
map to `+/*+`.
If convention-based mapping is not flexible enough you can use the
If convention-based mapping is not flexible enough you can use the
`ServletRegistrationBean`, `FilterRegistrationBean` and `ServletListenerRegistrationBean`
`ServletRegistrationBean`, `FilterRegistrationBean` and `ServletListenerRegistrationBean`
...
@@ -1293,9 +1296,9 @@ the `ServletContextInitializer` interface.
...
@@ -1293,9 +1296,9 @@ the `ServletContextInitializer` interface.
[[boot-features-embedded-container-application-context]]
[[boot-features-embedded-container-application-context]]
==== The EmbeddedWebApplicationContext
==== The EmbeddedWebApplicationContext
Under the hood Spring Boot uses a new type of `ApplicationContext` for embedded
Under the hood Spring Boot uses a new type of `ApplicationContext` for embedded
servlet
servlet container support. The `EmbeddedWebApplicationContext` is a special
container support. The `EmbeddedWebApplicationContext` is a special type of
type of
`WebApplicationContext` that bootstraps itself by searching for a single
`WebApplicationContext` that bootstraps itself by searching for a single
`EmbeddedServletContainerFactory` bean. Usually a `TomcatEmbeddedServletContainerFactory`,
`EmbeddedServletContainerFactory` bean. Usually a `TomcatEmbeddedServletContainerFactory`,
`JettyEmbeddedServletContainerFactory`, or `UndertowEmbeddedServletContainerFactory` will
`JettyEmbeddedServletContainerFactory`, or `UndertowEmbeddedServletContainerFactory` will
have been auto-configured.
have been auto-configured.
...
@@ -1325,8 +1328,8 @@ class for a complete list.
...
@@ -1325,8 +1328,8 @@ class for a complete list.
[[boot-features-programmatic-embedded-container-customization]]
[[boot-features-programmatic-embedded-container-customization]]
===== Programmatic customization
===== Programmatic customization
If you need to configure your embdedded servlet container programmatically you can
register
If you need to configure your embdedded servlet container programmatically you can
a Spring bean that implements the `EmbeddedServletContainerCustomizer` interface.
register
a Spring bean that implements the `EmbeddedServletContainerCustomizer` interface.
`EmbeddedServletContainerCustomizer` provides access to the
`EmbeddedServletContainerCustomizer` provides access to the
`ConfigurableEmbeddedServletContainer` which includes numerous customization setter
`ConfigurableEmbeddedServletContainer` which includes numerous customization setter
methods.
methods.
...
@@ -1386,8 +1389,8 @@ packaged as an executable archive), there are some limitations in the JSP suppor
...
@@ -1386,8 +1389,8 @@ packaged as an executable archive), there are some limitations in the JSP suppor
* 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
you
can see how to set things up.
can see how to set things up.
...
@@ -1411,8 +1414,8 @@ NOTE: If you fine tune your logging configuration, ensure that the
...
@@ -1411,8 +1414,8 @@ NOTE: If you fine tune your logging configuration, ensure that the
`org.springframework.boot.autoconfigure.security` category is set to log `INFO` messages,
`org.springframework.boot.autoconfigure.security` category is set to log `INFO` messages,
otherwise the default password will not be printed.
otherwise the default password will not be printed.
You can change the password by providing a `security.user.password`. This and other
You can change the password by providing a `security.user.password`. This and other
useful
useful
properties are externalized via
properties are externalized via
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
(properties prefix "security").
(properties prefix "security").
...
@@ -1458,7 +1461,6 @@ if you _do_ want to override the actuator access rules.
...
@@ -1458,7 +1461,6 @@ if you _do_ want to override the actuator access rules.
[[boot-features-sql]]
[[boot-features-sql]]
== Working with SQL databases
== Working with SQL databases
The Spring Framework provides extensive support for working with SQL databases. From
The Spring Framework provides extensive support for working with SQL databases. From
...
@@ -1484,13 +1486,13 @@ Obviously, in-memory databases do not provide persistent storage; you will need
...
@@ -1484,13 +1486,13 @@ Obviously, in-memory databases do not provide persistent storage; you will need
populate your database when your application starts and be prepared to throw away
populate your database when your application starts and be prepared to throw away
data when your application ends.
data when your application ends.
TIP: The '`How-to`' section includes a _<<howto.adoc#howto-database-initialization,
section
TIP: The '`How-to`' section includes a _<<howto.adoc#howto-database-initialization,
on how to initialize a database>>_
section
on how to initialize a database>>_
Spring Boot can auto-configure embedded http://www.h2database.com[H2],
Spring Boot can auto-configure embedded http://www.h2database.com[H2],
http://hsqldb.org/[HSQL] and http://db.apache.org/derby/[Derby] databases. You don't
http://hsqldb.org/[HSQL] and http://db.apache.org/derby/[Derby] databases. You don't
need
need to provide any connection URLs, simply include a build dependency to th
e
to provide any connection URLs, simply include a build dependency to the embedded databas
e
embedded database
that you want to use.
that you want to use.
For example, typical POM dependencies would be:
For example, typical POM dependencies would be:
...
@@ -1515,8 +1517,8 @@ auto-configured. In this example it's pulled in transitively via
...
@@ -1515,8 +1517,8 @@ auto-configured. In this example it's pulled in transitively via
[[boot-features-connect-to-production-database]]
[[boot-features-connect-to-production-database]]
==== Connection to a production database
==== Connection to a production database
Production database connections can also be auto-configured using a pooling
Production database connections can also be auto-configured using a pooling
`DataSource`.
`DataSource`.
Here's the algorithm for choosing a specific implementation:
Here's the algorithm for choosing a specific implementation:
* We prefer the Tomcat pooling `DataSource` for its performance and concurrency, so if
* We prefer the Tomcat pooling `DataSource` for its performance and concurrency, so if
that is available we always choose it.
that is available we always choose it.
...
@@ -1531,8 +1533,8 @@ NOTE: Additional connection pools can always be configured manually. If you defi
...
@@ -1531,8 +1533,8 @@ NOTE: Additional connection pools can always be configured manually. If you defi
own `DataSource` bean, auto-configuration will not occur.
own `DataSource` bean, auto-configuration will not occur.
DataSource configuration is controlled by external configuration properties in
DataSource configuration is controlled by external configuration properties in
`+spring.datasource.*+`. For example, you might declare the following section
`+spring.datasource.*+`. For example, you might declare the following section
in
in
`application.properties`:
`application.properties`:
[source,properties,indent=0]
[source,properties,indent=0]
----
----
...
@@ -1543,9 +1545,9 @@ in `application.properties`:
...
@@ -1543,9 +1545,9 @@ in `application.properties`:
----
----
See {sc-spring-boot-autoconfigure}/jdbc/DataSourceProperties.{sc-ext}[`DataSourceProperties`]
See {sc-spring-boot-autoconfigure}/jdbc/DataSourceProperties.{sc-ext}[`DataSourceProperties`]
for more of the supported options. Note also that you can configure any of the
`DataSource`
for more of the supported options. Note also that you can configure any of the
implementation specific properties via `+spring.datasource.*+`: refer to the documentation
`DataSource` implementation specific properties via `+spring.datasource.*+`: refer to the
of the connection pool implementation you are using for more details.
documentation
of the connection pool implementation you are using for more details.
TIP: You often won't need to specify the `driver-class-name` since Spring boot can deduce
TIP: You often won't need to specify the `driver-class-name` since Spring boot can deduce
it for most databases from the `url`.
it for most databases from the `url`.
...
@@ -1624,8 +1626,8 @@ and http://hibernate.org/orm/documentation/[Hibernate] reference documentation.
...
@@ -1624,8 +1626,8 @@ and http://hibernate.org/orm/documentation/[Hibernate] reference documentation.
[[boot-features-entity-classes]]
[[boot-features-entity-classes]]
==== Entity Classes
==== Entity Classes
Traditionally, JPA '`Entity`' classes are specified in a `persistence.xml` file. With
Traditionally, JPA '`Entity`' classes are specified in a `persistence.xml` file. With
Spring Boot this file is not necessary and instead '`Entity Scanning`' is used. By
Spring Boot this file is not necessary and instead '`Entity Scanning`' is used. By
default
default
all packages below your main configuration class (the one annotated with
all packages below your main configuration class (the one annotated with
`@EnableAutoConfiguration` or `@SpringBootApplication`) will be searched.
`@EnableAutoConfiguration` or `@SpringBootApplication`) will be searched.
Any classes annotated with `@Entity`, `@Embeddable` or `@MappedSuperclass` will be
Any classes annotated with `@Entity`, `@Embeddable` or `@MappedSuperclass` will be
...
@@ -1676,27 +1678,27 @@ considered. A typical entity class would look something like this:
...
@@ -1676,27 +1678,27 @@ considered. A typical entity class would look something like this:
}
}
----
----
TIP: You can customize entity scanning locations using the `@EntityScan` annotation.
TIP: You can customize entity scanning locations using the `@EntityScan` annotation.
See
See the _<<howto.adoc#howto-separate-entity-definitions-from-spring-configuration>>_
the _<<howto.adoc#howto-separate-entity-definitions-from-spring-configuration>>_ how-to.
how-to.
[[boot-features-spring-data-jpa-repositories]]
[[boot-features-spring-data-jpa-repositories]]
==== Spring Data JPA Repositories
==== Spring Data JPA Repositories
Spring Data JPA repositories are interfaces that you can define to access data. JPA
Spring Data JPA repositories are interfaces that you can define to access data. JPA
queries are created automatically from your method names. For example, a `CityRepository`
queries are created automatically from your method names. For example, a `CityRepository`
interface might declare a `findAllByState(String state)` method to find all cities
interface might declare a `findAllByState(String state)` method to find all cities
in a
in a
given state.
given state.
For more complex queries you can annotate your method using Spring Data's
For more complex queries you can annotate your method using Spring Data's
{spring-data-javadoc}/repository/Query.html[`Query`] annotation.
{spring-data-javadoc}/repository/Query.html[`Query`] annotation.
Spring Data repositories usually extend from the
Spring Data repositories usually extend from the
{spring-data-commons-javadoc}/repository/Repository.html[`Repository`] or
{spring-data-commons-javadoc}/repository/Repository.html[`Repository`] or
{spring-data-commons-javadoc}/repository/CrudRepository.html[`CrudRepository`] interfaces.
If you are using
{spring-data-commons-javadoc}/repository/CrudRepository.html[`CrudRepository`] interfaces.
auto-configuration, repositories will be searched from the package containing your
If you are using auto-configuration, repositories will be searched from the package
main configuration class (the one annotated with `@EnableAutoConfiguration` or
containing your main configuration class (the one annotated with
`@SpringBootApplication`) down.
`@
EnableAutoConfiguration` or `@
SpringBootApplication`) down.
Here is a typical Spring Data repository:
Here is a typical Spring Data repository:
...
@@ -1745,10 +1747,9 @@ to the entity manager). Example:
...
@@ -1745,10 +1747,9 @@ to the entity manager). Example:
passes `hibernate.globally_quoted_identifiers` to the Hibernate entity manager.
passes `hibernate.globally_quoted_identifiers` to the Hibernate entity manager.
By default the DDL execution (or validation) is deferred until
By default the DDL execution (or validation) is deferred until the `ApplicationContext`
the `ApplicationContext` has started. There is also a `spring.jpa.generate-ddl` flag, but
has started. There is also a `spring.jpa.generate-ddl` flag, but it is not used if
it is not used if Hibernate autoconfig is active because the `ddl-auto`
Hibernate autoconfig is active because the `ddl-auto` settings are more fine-grained.
settings are more fine-grained.
...
@@ -1764,9 +1765,9 @@ http://projects.spring.io/spring-data-redis/[Redis],
...
@@ -1764,9 +1765,9 @@ http://projects.spring.io/spring-data-redis/[Redis],
http://projects.spring.io/spring-data-gemfire/[Gemfire],
http://projects.spring.io/spring-data-gemfire/[Gemfire],
http://projects.spring.io/spring-data-couchbase/[Couchbase] and
http://projects.spring.io/spring-data-couchbase/[Couchbase] and
http://projects.spring.io/spring-data-cassandra/[Cassandra].
http://projects.spring.io/spring-data-cassandra/[Cassandra].
Spring Boot provides auto-configuration for Redis, MongoDB, Elasticsearch,
Solr and
Spring Boot provides auto-configuration for Redis, MongoDB, Elasticsearch,
and Solr; you
Gemfire; you can make use of the other projects, but you will need to configure them
can make use of the other projects, but you will need to configure them yourself. Refer to
yourself. Refer to
the appropriate reference documentation at
the appropriate reference documentation at
http://projects.spring.io/spring-data[projects.spring.io/spring-data].
http://projects.spring.io/spring-data[projects.spring.io/spring-data].
...
@@ -1774,10 +1775,10 @@ http://projects.spring.io/spring-data[projects.spring.io/spring-data].
...
@@ -1774,10 +1775,10 @@ http://projects.spring.io/spring-data[projects.spring.io/spring-data].
[[boot-features-redis]]
[[boot-features-redis]]
=== Redis
=== Redis
http://redis.io/[Redis] is a cache, message broker and richly-featured key-value store.
http://redis.io/[Redis] is a cache, message broker and richly-featured key-value store.
Spring Boot offers basic auto-configuration for the
https://github.com/xetorthio/jedis/[Jedis]
Spring Boot offers basic auto-configuration for the
client library and abstractions on top of it provided by
https://github.com/xetorthio/jedis/[Jedis] client library and abstractions on top of it
https://github.com/spring-projects/spring-data-redis[Spring Data Redis]. There is a
provided by https://github.com/spring-projects/spring-data-redis[Spring Data Redis]. There
`spring-boot-starter-redis` '`Starter POM`' for collecting the dependencies in a
is a
`spring-boot-starter-redis` '`Starter POM`' for collecting the dependencies in a
convenient way.
convenient way.
...
@@ -1824,8 +1825,8 @@ several conveniences for working with MongoDB, including the
...
@@ -1824,8 +1825,8 @@ several conveniences for working with MongoDB, including 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 `org.springframework.data.mongodb.MongoDbFactory` to
You can inject an auto-configured `org.springframework.data.mongodb.MongoDbFactory` to
access Mongo databases. By default the instance will attempt to connect to a MongoDB
server
access Mongo databases. By default the instance will attempt to connect to a MongoDB
using the URL `mongodb://localhost/test`:
server
using the URL `mongodb://localhost/test`:
[source,java,indent=0]
[source,java,indent=0]
----
----
...
@@ -1875,9 +1876,10 @@ complete control of establishing the MongoDB connection.
...
@@ -1875,9 +1876,10 @@ complete control of establishing the MongoDB connection.
[[boot-features-mongo-template]]
[[boot-features-mongo-template]]
==== MongoTemplate
==== MongoTemplate
Spring Data Mongo provides a {spring-data-mongo-javadoc}/core/MongoTemplate.html[`MongoTemplate`]
Spring Data Mongo provides a
class that is very similar in its design to Spring's `JdbcTemplate`. As with
{spring-data-mongo-javadoc}/core/MongoTemplate.html[`MongoTemplate`] class that is very
`JdbcTemplate` Spring Boot auto-configures a bean for you to simply inject:
similar in its design to Spring's `JdbcTemplate`. As with `JdbcTemplate` Spring Boot
auto-configures a bean for you to simply inject:
[source,java,indent=0]
[source,java,indent=0]
----
----
...
@@ -1911,9 +1913,8 @@ discussed earlier, the basic principle is that queries are constructed for you
...
@@ -1911,9 +1913,8 @@ discussed earlier, the basic principle is that queries are constructed for you
automatically based on method names.
automatically based on method names.
In fact, both Spring Data JPA and Spring Data MongoDB share the same common
In fact, both Spring Data JPA and Spring Data MongoDB share the same common
infrastructure; so you could take the JPA example from earlier and, assuming that
infrastructure; so you could take the JPA example from earlier and, assuming that `City`
`City` is now a Mongo data class rather than a JPA `@Entity`, it will work in the
is now a Mongo data class rather than a JPA `@Entity`, it will work in the same way.
same way.
[source,java,indent=0]
[source,java,indent=0]
----
----
...
@@ -1940,10 +1941,11 @@ documentation].
...
@@ -1940,10 +1941,11 @@ documentation].
[[boot-features-gemfire]]
[[boot-features-gemfire]]
=== Gemfire
=== Gemfire
https://github.com/spring-projects/spring-data-gemfire[Spring Data Gemfire] provides
https://github.com/spring-projects/spring-data-gemfire[Spring Data Gemfire] provides
convenient Spring-friendly tools for accessing the http://www.gopivotal.com/big-data/pivotal-gemfire#details[Pivotal Gemfire]
convenient Spring-friendly tools for accessing the
data management platform. There is a `spring-boot-starter-data-gemfire` '`Starter POM`'
http://www.gopivotal.com/big-data/pivotal-gemfire#details[Pivotal Gemfire] data management
for collecting the dependencies in a convenient way. There is currently no auto-configuration
platform. There is a `spring-boot-starter-data-gemfire` '`Starter POM`' for collecting the
support for Gemfire, but you can enable Spring Data Repositories with a
dependencies in a convenient way. There is currently no auto-configuration support for
Gemfire, but you can enable Spring Data Repositories with a
https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/config/EnableGemfireRepositories.java[single annotation (`@EnableGemfireRepositories`)].
https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/config/EnableGemfireRepositories.java[single annotation (`@EnableGemfireRepositories`)].
...
@@ -1961,7 +1963,7 @@ convenient way.
...
@@ -1961,7 +1963,7 @@ convenient way.
[[boot-features-connecting-to-solr]]
[[boot-features-connecting-to-solr]]
==== Connecting to Solr
==== Connecting to Solr
You can inject an auto-configured `SolrServer` instance as you would any other Spring
You can inject an auto-configured `SolrServer` instance as you would any other Spring
B
ean. By default the instance will attempt to connect to a server using
b
ean. By default the instance will attempt to connect to a server using
`http://localhost:8983/solr`:
`http://localhost:8983/solr`:
[source,java,indent=0]
[source,java,indent=0]
...
@@ -2062,10 +2064,10 @@ http://docs.spring.io/spring-data/elasticsearch/docs/[reference documentation].
...
@@ -2062,10 +2064,10 @@ http://docs.spring.io/spring-data/elasticsearch/docs/[reference documentation].
The Spring Framework provides extensive support for integrating with messaging systems:
The Spring Framework provides extensive support for integrating with messaging systems:
from simplified use of the JMS API using `JmsTemplate` to a complete infrastructure to
from simplified use of the JMS API using `JmsTemplate` to a complete infrastructure to
receive messages asynchronously. Spring AMQP provides a similar feature set for the
receive messages asynchronously. Spring AMQP provides a similar feature set for the
'`Advanced Message Queuing Protocol`' and Spring Boot also provides auto-configuration
options
'`Advanced Message Queuing Protocol`' and Spring Boot also provides auto-configuration
for `RabbitTemplate` and RabbitMQ. There is also support for STOMP messaging natively
options for `RabbitTemplate` and RabbitMQ. There is also support for STOMP messaging
in Spring WebSocket and Spring Boot has support for that through starters and a small
natively in Spring WebSocket and Spring Boot has support for that through starters and a
amount of auto-configuration.
small
amount of auto-configuration.
...
@@ -2087,10 +2089,10 @@ Spring Boot can auto-configure a `ConnectionFactory` when it detects that Hornet
...
@@ -2087,10 +2089,10 @@ Spring Boot can auto-configure a `ConnectionFactory` when it detects that Hornet
available on the classpath. If the broker is present, an embedded broker is started and
available on the classpath. If the broker is present, an embedded broker is started and
configured automatically (unless the mode property has been explicitly set). The supported
configured automatically (unless the mode property has been explicitly set). The supported
modes are: `embedded` (to make explicit that an embedded broker is required and should
modes are: `embedded` (to make explicit that an embedded broker is required and should
lead to an error if the broker is not available in the classpath), and `native` to
lead to an error if the broker is not available in the classpath), and `native` to
connect
connect to a broker using the `netty` transport protocol. When the latter is
to a broker using the `netty` transport protocol. When the latter is configured, Spring
configured, Spring Boot configures a `ConnectionFactory` connecting to a broker running
Boot configures a `ConnectionFactory` connecting to a broker running on the local machine
on the local machine
with the default settings.
with the default settings.
NOTE: If you are using `spring-boot-starter-hornetq` the necessary dependencies to
NOTE: If you are using `spring-boot-starter-hornetq` the necessary dependencies to
connect to an existing HornetQ instance are provided, as well as the Spring infrastructure
connect to an existing HornetQ instance are provided, as well as the Spring infrastructure
...
@@ -2115,7 +2117,8 @@ list to create them with the default options; or you can define bean(s) of type
...
@@ -2115,7 +2117,8 @@ list to create them with the default options; or you can define bean(s) of type
`org.hornetq.jms.server.config.TopicConfiguration`, for advanced queue and topic
`org.hornetq.jms.server.config.TopicConfiguration`, for advanced queue and topic
configurations respectively.
configurations respectively.
See {sc-spring-boot-autoconfigure}/jms/hornetq/HornetQProperties.{sc-ext}[`HornetQProperties`]
See
{sc-spring-boot-autoconfigure}/jms/hornetq/HornetQProperties.{sc-ext}[`HornetQProperties`]
for more of the supported options.
for more of the supported options.
No JNDI lookup is involved at all and destinations are resolved against their names,
No JNDI lookup is involved at all and destinations are resolved against their names,
...
@@ -2141,7 +2144,8 @@ ActiveMQ configuration is controlled by external configuration properties in
...
@@ -2141,7 +2144,8 @@ ActiveMQ configuration is controlled by external configuration properties in
spring.activemq.password=secret
spring.activemq.password=secret
----
----
See {sc-spring-boot-autoconfigure}/jms/activemq/ActiveMQProperties.{sc-ext}[`ActiveMQProperties`]
See
{sc-spring-boot-autoconfigure}/jms/activemq/ActiveMQProperties.{sc-ext}[`ActiveMQProperties`]
for more of the supported options.
for more of the supported options.
By default, ActiveMQ creates a destination if it does not exist yet, so destinations are
By default, ActiveMQ creates a destination if it does not exist yet, so destinations are
...
@@ -2166,8 +2170,8 @@ locate a JMS `ConnectionFactory` using JNDI. By default the locations `java:/Jms
...
@@ -2166,8 +2170,8 @@ locate a JMS `ConnectionFactory` using JNDI. By default the locations `java:/Jms
[[boot-features-using-jms-template]]
[[boot-features-using-jms-template]]
[[boot-features-using-jms-sending]]
[[boot-features-using-jms-sending]]
==== Sending a message
==== Sending a message
Spring's `JmsTemplate` is auto-configured and you can autowire it directly into your
Spring's `JmsTemplate` is auto-configured and you can autowire it directly into your
own
own
beans:
beans:
[source,java,indent=0]
[source,java,indent=0]
----
----
...
@@ -2199,8 +2203,8 @@ NOTE: {spring-javadoc}/jms/core/JmsMessagingTemplate.{dc-ext}[`JmsMessagingTempl
...
@@ -2199,8 +2203,8 @@ NOTE: {spring-javadoc}/jms/core/JmsMessagingTemplate.{dc-ext}[`JmsMessagingTempl
==== Receiving a message
==== Receiving a message
When the JMS infrastructure is present, any bean can be annotated with `@JmsListener` to
When the JMS infrastructure is present, any bean can be annotated with `@JmsListener` to
create a listener endpoint. If no `JmsListenerContainerFactory` has been defined, a
default
create a listener endpoint. If no `JmsListenerContainerFactory` has been defined, a
one is configured automatically.
default
one is configured automatically.
The following component creates a listener endpoint on the `someQueue` destination:
The following component creates a listener endpoint on the `someQueue` destination:
...
@@ -2217,8 +2221,8 @@ The following component creates a listener endpoint on the `someQueue` destinati
...
@@ -2217,8 +2221,8 @@ The following component creates a listener endpoint on the `someQueue` destinati
}
}
----
----
Check {spring-javadoc}/jms/annotation/EnableJms.{dc-ext}[the Javadoc of `@EnableJms`]
Check {spring-javadoc}/jms/annotation/EnableJms.{dc-ext}[the Javadoc of `@EnableJms`]
for
for
more details.
more details.
...
@@ -2231,9 +2235,10 @@ a starter module.
...
@@ -2231,9 +2235,10 @@ a starter module.
TIP: Check the {spring-reference}/#mail[reference documentation] for a detailed
TIP: Check the {spring-reference}/#mail[reference documentation] for a detailed
explanation of how you can use `JavaMailSender`.
explanation of how you can use `JavaMailSender`.
If `spring.mail.host` and the relevant libraries (as defined by `spring-boot-starter-mail`)
If `spring.mail.host` and the relevant libraries (as defined by
are available, a default `JavaMailSender` is created if none exists. The sender can be
`spring-boot-starter-mail`) are available, a default `JavaMailSender` is created if none
further customized by configuration items from the `spring.mail` namespace, see the
exists. The sender can be further customized by configuration items from the `spring.mail`
namespace, see the
{sc-spring-boot-autoconfigure}/mail/MailProperties.{sc-ext}[`MailProperties`] for more
{sc-spring-boot-autoconfigure}/mail/MailProperties.{sc-ext}[`MailProperties`] for more
details.
details.
...
@@ -2246,9 +2251,9 @@ either an http://www.atomikos.com/[Atomikos] or
...
@@ -2246,9 +2251,9 @@ either an http://www.atomikos.com/[Atomikos] or
http://docs.codehaus.org/display/BTM/Home[Bitronix] embedded transaction manager. JTA
http://docs.codehaus.org/display/BTM/Home[Bitronix] embedded transaction manager. JTA
transactions are also supported when deploying to a suitable Java EE Application Server.
transactions are also supported when deploying to a suitable Java EE Application Server.
When a JTA environment is detected, Spring's `JtaTransactionManager` will be used to
manage
When a JTA environment is detected, Spring's `JtaTransactionManager` will be used to
transactions. Auto-configured JMS, DataSource and JPA beans will be upgraded to support
manage transactions. Auto-configured JMS, DataSource and JPA beans will be upgraded to
XA transactions. You can use standard Spring idioms such as `@Transactional` to
support
XA transactions. You can use standard Spring idioms such as `@Transactional` to
participate in a distributed transaction. If you are within a JTA environment and still
participate in a distributed transaction. If you are within a JTA environment and still
want to use local transactions you can set the `spring.jta.enabled` property to `false` to
want to use local transactions you can set the `spring.jta.enabled` property to `false` to
disable the JTA auto-configuration.
disable the JTA auto-configuration.
...
@@ -2289,8 +2294,9 @@ By default Bitronix transaction log files (`part1.btm` and `part2.btm`) will be
...
@@ -2289,8 +2294,9 @@ By default Bitronix transaction log files (`part1.btm` and `part2.btm`) will be
a `transaction-logs` directory in your application home directory. You can customize this
a `transaction-logs` directory in your application home directory. You can customize this
directory by using the `spring.jta.log-dir` property. Properties starting `spring.jta.`
directory by using the `spring.jta.log-dir` property. Properties starting `spring.jta.`
are also bound to the `bitronix.tm.Configuration` bean, allowing for complete
are also bound to the `bitronix.tm.Configuration` bean, allowing for complete
customization. See the http://btm.codehaus.org/api/2.0.1/bitronix/tm/Configuration.html[Bitronix
customization. See the
documentation] for details.
http://btm.codehaus.org/api/2.0.1/bitronix/tm/Configuration.html[Bitronix documentation]
for details.
NOTE: To ensure that multiple transaction managers can safely coordinate the same
NOTE: To ensure that multiple transaction managers can safely coordinate the same
resource managers, each Bitronix instance must be configured with a unique ID. By default
resource managers, each Bitronix instance must be configured with a unique ID. By default
...
@@ -2368,8 +2374,8 @@ provide good examples of how to write XA wrappers.
...
@@ -2368,8 +2374,8 @@ provide good examples of how to write XA wrappers.
Spring Integration provides abstractions over messaging and also other transports such as
Spring Integration provides abstractions over messaging and also other transports such as
HTTP, TCP etc. If Spring Integration is available on your classpath it will be initialized
HTTP, TCP etc. If Spring Integration is available on your classpath it will be initialized
through the `@EnableIntegration` annotation. Message processing statistics will be
through the `@EnableIntegration` annotation. Message processing statistics will be
published over JMX if `'spring-integration-jmx'` is also on the classpath.
published over JMX if `'spring-integration-jmx'` is also on the classpath.
See the
See the
{sc-spring-boot-autoconfigure}/integration/IntegrationAutoConfiguration.{sc-ext}[`IntegrationAutoConfiguration`]
{sc-spring-boot-autoconfigure}/integration/IntegrationAutoConfiguration.{sc-ext}[`IntegrationAutoConfiguration`]
class for more details.
class for more details.
...
@@ -2381,7 +2387,8 @@ applications. By default Spring Boot will create an `MBeanServer` with bean id
...
@@ -2381,7 +2387,8 @@ applications. By default Spring Boot will create an `MBeanServer` with bean id
'`mbeanServer`' and expose any of your beans that are annotated with Spring JMX
'`mbeanServer`' and expose any of your beans that are annotated with Spring JMX
annotations (`@ManagedResource`, `@ManagedAttribute`, `@ManagedOperation`).
annotations (`@ManagedResource`, `@ManagedAttribute`, `@ManagedOperation`).
See the {sc-spring-boot-autoconfigure}/jmx/JmxAutoConfiguration.{sc-ext}[`JmxAutoConfiguration`]
See the
{sc-spring-boot-autoconfigure}/jmx/JmxAutoConfiguration.{sc-ext}[`JmxAutoConfiguration`]
class for more details.
class for more details.
...
@@ -2390,8 +2397,8 @@ class for more details.
...
@@ -2390,8 +2397,8 @@ class for more details.
== Testing
== Testing
Spring Boot provides a number of useful tools for testing your application. The
Spring Boot provides a number of useful tools for testing your application. The
`spring-boot-starter-test` POM provides Spring Test, JUnit, Hamcrest and Mockito
`spring-boot-starter-test` POM provides Spring Test, JUnit, Hamcrest and Mockito
dependencies. There are also useful test utilities in the core `spring-boot` module
dependencies. There are also useful test utilities in the core `spring-boot` module
under
under
the `org.springframework.boot.test` package.
the `org.springframework.boot.test` package.
...
@@ -2611,12 +2618,12 @@ public class MyTest {
...
@@ -2611,12 +2618,12 @@ public class MyTest {
[[boot-features-rest-templates-test-utility]]
[[boot-features-rest-templates-test-utility]]
==== TestRestTemplate
==== TestRestTemplate
`TestRestTemplate` is a convenience subclass of Spring's `RestTemplate` that is
`TestRestTemplate` is a convenience subclass of Spring's `RestTemplate` that is
useful in
useful in integration tests.
You can get a vanilla template or one that sends Basic HTTP
integration tests.
You can get a vanilla template or one that sends Basic HTTP
authentication (with a username and password). In either case the template will behave
authentication (with a username and password). In either case the template will behave
in a test-friendly way: not following redirects (so you can assert the response
in a test-friendly way: not following redirects (so you can assert the response
location),
location), ignoring cookies (so the template is stateless), and not throwing exceptions
ignoring cookies (so the template is stateless), and not throwing exceptions on
on
server-side errors. It is recommended, but not mandatory, to use Apache HTTP Client
server-side errors. It is recommended, but not mandatory, to use Apache HTTP Client
(version 4.3.2 or better), and if you have that on your classpath the `TestRestTemplate`
(version 4.3.2 or better), and if you have that on your classpath the `TestRestTemplate`
will respond by configuring the client appropriately.
will respond by configuring the client appropriately.
...
@@ -2651,9 +2658,8 @@ Spring Boot.
...
@@ -2651,9 +2658,8 @@ Spring Boot.
Under the hood, auto-configuration is implemented with standard `@Configuration` classes.
Under the hood, auto-configuration is implemented with standard `@Configuration` classes.
Additional `@Conditional` annotations are used to constrain when the auto-configuration
Additional `@Conditional` annotations are used to constrain when the auto-configuration
should apply. Usually auto-configuration classes use `@ConditionalOnClass` and
should apply. Usually auto-configuration classes use `@ConditionalOnClass` and
`@ConditionalOnMissingBean` annotations. This ensures that auto-configuration only
`@ConditionalOnMissingBean` annotations. This ensures that auto-configuration only applies
applies when relevant classes are found and when you have not declared your own
when relevant classes are found and when you have not declared your own `@Configuration`.
`@Configuration`.
You can browse the source code of `spring-boot-autoconfigure` to see the `@Configuration`
You can browse the source code of `spring-boot-autoconfigure` to see the `@Configuration`
classes that we provide (see the `META-INF/spring.factories` file).
classes that we provide (see the `META-INF/spring.factories` file).
...
@@ -2676,8 +2682,8 @@ published jar. The file should list your configuration classes under the
...
@@ -2676,8 +2682,8 @@ published jar. The file should list your configuration classes under the
You can use the
You can use the
{sc-spring-boot-autoconfigure}/AutoConfigureAfter.{sc-ext}[`@AutoConfigureAfter`] or
{sc-spring-boot-autoconfigure}/AutoConfigureAfter.{sc-ext}[`@AutoConfigureAfter`] or
{sc-spring-boot-autoconfigure}/AutoConfigureBefore.{sc-ext}[`@AutoConfigureBefore`]
{sc-spring-boot-autoconfigure}/AutoConfigureBefore.{sc-ext}[`@AutoConfigureBefore`]
annotations if your configuration needs to be applied in a specific order. For example,
annotations if your configuration needs to be applied in a specific order. For example,
if
if
you provide web-specific configuration, your class may need to be applied after
you provide web-specific configuration, your class may need to be applied after
`WebMvcAutoConfiguration`.
`WebMvcAutoConfiguration`.
...
@@ -2696,12 +2702,12 @@ code by annotating `@Configuration` classes or individual `@Bean` methods.
...
@@ -2696,12 +2702,12 @@ code by annotating `@Configuration` classes or individual `@Bean` methods.
[[boot-features-class-conditions]]
[[boot-features-class-conditions]]
==== Class conditions
==== Class conditions
The `@ConditionalOnClass` and `@ConditionalOnMissingClass` annotations allows
configuration
The `@ConditionalOnClass` and `@ConditionalOnMissingClass` annotations allows
to be included based on the presence or absence of specific classes. Due to the fact that
configuration to be included based on the presence or absence of specific classes. Due to
annotation metadata is parsed using http://asm.ow2.org/[ASM] you can actually use the
the fact that annotation metadata is parsed using http://asm.ow2.org/[ASM] you can
`value` attribute to refer to the real class, even though that class might not actually
actually use the `value` attribute to refer to the real class, even though that class
appear on the running application classpath. You can also use the `name` attribute if you
might not actually appear on the running application classpath. You can also use the
prefer to specify the class name using a `String` value.
`name` attribute if you
prefer to specify the class name using a `String` value.
...
@@ -2713,10 +2719,10 @@ attribute to specify beans by type, or `name` to specify beans by name. The `sea
...
@@ -2713,10 +2719,10 @@ attribute to specify beans by type, or `name` to specify beans by name. The `sea
attribute allows you to limit the `ApplicationContext` hierarchy that should be considered
attribute allows you to limit the `ApplicationContext` hierarchy that should be considered
when searching for beans.
when searching for beans.
NOTE: `@Conditional` annotations are processed when `@Configuration` classes are
NOTE: `@Conditional` annotations are processed when `@Configuration` classes are
parsed.
parsed. Auto-configured `@Configuration` is always parsed last (after any user defined
Auto-configured `@Configuration` is always parsed last (after any user defined beans),
beans), however, if you are using these annotations on regular `@Configuration` classes,
however, if you are using these annotations on regular `@Configuration` classes, care must
care must
be taken not to refer to bean definitions that have not yet been created.
be taken not to refer to bean definitions that have not yet been created.
...
@@ -2741,8 +2747,8 @@ conventions, for example, `file:/home/user/test.dat`.
...
@@ -2741,8 +2747,8 @@ conventions, for example, `file:/home/user/test.dat`.
[[boot-features-web-application-conditions]]
[[boot-features-web-application-conditions]]
==== Web application conditions
==== Web application conditions
The `@ConditionalOnWebApplication` and `@ConditionalOnNotWebApplication` annotations
The `@ConditionalOnWebApplication` and `@ConditionalOnNotWebApplication` annotations
allow configuration to be included depending on whether the application is a
allow configuration to be included depending on whether the application is a
'web
'web
application'. A web application is any application that is using a Spring
application'. A web application is any application that is using a Spring
`WebApplicationContext`, defines a `session` scope or has a `StandardServletEnvironment`.
`WebApplicationContext`, defines a `session` scope or has a `StandardServletEnvironment`.
...
@@ -2775,4 +2781,3 @@ check out the {dc-root}[Spring Boot API documentation] or you can browse the
...
@@ -2775,4 +2781,3 @@ check out the {dc-root}[Spring Boot API documentation] or you can browse the
If you are comfortable with Spring Boot's core features, you can carry on and read
If you are comfortable with Spring Boot's core features, you can carry on and read
about <<production-ready-features.adoc#production-ready, production-ready features>>.
about <<production-ready-features.adoc#production-ready, production-ready features>>.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment