mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Fix various minor inconsistencies in the documentation
See gh-40900
This commit is contained in:
parent
96cfc14546
commit
ab2ba674b6
@ -41,7 +41,7 @@ When reading the code, remember the following rules of thumb:
|
||||
|
||||
* Look for classes called `+*AutoConfiguration+` and read their sources.
|
||||
Pay special attention to the `+@Conditional*+` annotations to find out what features they enable and when.
|
||||
Add `--debug` to the command line or a System property `-Ddebug` to get a log on the console of all the auto-configuration decisions that were made in your app.
|
||||
Add `--debug` to the command line or the System property `-Ddebug` to get a log on the console of all the auto-configuration decisions that were made in your app.
|
||||
In a running application with actuator enabled, look at the `conditions` endpoint (`/actuator/conditions` or the JMX equivalent) for the same information.
|
||||
* Look for classes that are `@ConfigurationProperties` (such as {spring-boot-autoconfigure-module-code}/web/ServerProperties.java[`ServerProperties`]) and read from there the available external configuration options.
|
||||
The `@ConfigurationProperties` annotation has a `name` attribute that acts as a prefix to external properties.
|
||||
@ -103,5 +103,5 @@ Not all Spring applications have to be web applications (or web services).
|
||||
If you want to execute some code in a `main` method but also bootstrap a Spring application to set up the infrastructure to use, you can use the `SpringApplication` features of Spring Boot.
|
||||
A `SpringApplication` changes its `ApplicationContext` class, depending on whether it thinks it needs a web application or not.
|
||||
The first thing you can do to help it is to leave server-related dependencies (such as the servlet API) off the classpath.
|
||||
If you cannot do that (for example, you run two applications from the same code base) then you can explicitly call `setWebApplicationType(WebApplicationType.NONE)` on your `SpringApplication` instance or set the `applicationContextClass` property (through the Java API or with external properties).
|
||||
If you cannot do that (for example, if you run two applications from the same code base) then you can explicitly call `setWebApplicationType(WebApplicationType.NONE)` on your `SpringApplication` instance or set the `applicationContextClass` property (through the Java API or with external properties).
|
||||
Application code that you want to run as your business logic can be implemented as a `CommandLineRunner` and dropped into the context as a `@Bean` definition.
|
||||
|
@ -15,7 +15,7 @@ The following example shows how to define a data source in a bean:
|
||||
|
||||
include::code:custom/MyDataSourceConfiguration[]
|
||||
|
||||
The following example shows how to define a data source by setting properties:
|
||||
The following example shows how to define a data source by setting its properties:
|
||||
|
||||
[source,yaml,indent=0,subs="verbatim",configblocks]
|
||||
----
|
||||
@ -29,7 +29,7 @@ The following example shows how to define a data source by setting properties:
|
||||
Assuming that `SomeDataSource` has regular JavaBean properties for the URL, the username, and the pool size, these settings are bound automatically before the `DataSource` is made available to other components.
|
||||
|
||||
Spring Boot also provides a utility builder class, called `DataSourceBuilder`, that can be used to create one of the standard data sources (if it is on the classpath).
|
||||
The builder can detect the one to use based on what is available on the classpath.
|
||||
The builder can detect which one to use based on what is available on the classpath.
|
||||
It also auto-detects the driver based on the JDBC URL.
|
||||
|
||||
The following example shows how to create a data source by using a `DataSourceBuilder`:
|
||||
@ -70,7 +70,7 @@ In that case, you must rewrite your configuration as follows:
|
||||
You can fix that by forcing the connection pool to use and return a dedicated implementation rather than `DataSource`.
|
||||
You cannot change the implementation at runtime, but the list of options will be explicit.
|
||||
|
||||
The following example shows how create a `HikariDataSource` with `DataSourceBuilder`:
|
||||
The following example shows how to create a `HikariDataSource` with `DataSourceBuilder`:
|
||||
|
||||
include::code:simple/MyDataSourceConfiguration[]
|
||||
|
||||
@ -107,7 +107,7 @@ See "`<<data#data.sql.datasource>>`" in the "`Spring Boot features`" section and
|
||||
|
||||
[[howto.data-access.configure-two-datasources]]
|
||||
=== Configure Two DataSources
|
||||
If you need to configure multiple data sources, you can apply the same tricks that are described in the previous section.
|
||||
If you need to configure multiple data sources, you can apply the same tricks that were described in the previous section.
|
||||
You must, however, mark one of the `DataSource` instances as `@Primary`, because various auto-configurations down the road expect to be able to get one by type.
|
||||
|
||||
If you create your own `DataSource`, the auto-configuration backs off.
|
||||
@ -208,7 +208,7 @@ If you use other forms, such as `batchSize` or `batch-size`, Hibernate will not
|
||||
====
|
||||
|
||||
TIP: If you need to apply advanced customization to Hibernate properties, consider registering a `HibernatePropertiesCustomizer` bean that will be invoked prior to creating the `EntityManagerFactory`.
|
||||
This takes precedence to anything that is applied by the auto-configuration.
|
||||
This takes precedence over anything that is applied by the auto-configuration.
|
||||
|
||||
|
||||
|
||||
@ -286,7 +286,7 @@ It scans entities located in the same package as `Order`.
|
||||
It is possible to map additional JPA properties using the `app.first.jpa` namespace.
|
||||
|
||||
NOTE: When you create a bean for `LocalContainerEntityManagerFactoryBean` yourself, any customization that was applied during the creation of the auto-configured `LocalContainerEntityManagerFactoryBean` is lost.
|
||||
For example, in case of Hibernate, any properties under the `spring.jpa.hibernate` prefix will not be automatically applied to your `LocalContainerEntityManagerFactoryBean`.
|
||||
For example, in the case of Hibernate, any properties under the `spring.jpa.hibernate` prefix will not be automatically applied to your `LocalContainerEntityManagerFactoryBean`.
|
||||
If you were relying on these properties for configuring things like the naming strategy or the DDL mode, you will need to explicitly configure that when creating the `LocalContainerEntityManagerFactoryBean` bean.
|
||||
|
||||
You should provide a similar configuration for any additional data sources for which you need JPA access.
|
||||
@ -349,7 +349,7 @@ If you need to specify an order, make sure it is higher than 0.
|
||||
=== Configure a Component that is Used by JPA
|
||||
If you want to configure a component that JPA uses, then you need to ensure that the component is initialized before JPA.
|
||||
When the component is auto-configured, Spring Boot takes care of this for you.
|
||||
For example, when Flyway is auto-configured, Hibernate is configured to depend upon Flyway so that Flyway has a chance to initialize the database before Hibernate tries to use it.
|
||||
For example, when Flyway is auto-configured, Hibernate is configured to depend on Flyway so that Flyway has a chance to initialize the database before Hibernate tries to use it.
|
||||
|
||||
If you are configuring a component yourself, you can use an `EntityManagerFactoryDependsOnPostProcessor` subclass as a convenient way of setting up the necessary dependencies.
|
||||
For example, if you use Hibernate Search with Elasticsearch as its index manager, any `EntityManagerFactory` beans must be configured to depend on the `elasticsearchClient` bean, as shown in the following example:
|
||||
|
@ -13,7 +13,7 @@ This is possible in both Maven and Gradle.
|
||||
|
||||
[[howto.properties-and-configuration.expand-properties.maven]]
|
||||
==== Automatic Property Expansion Using Maven
|
||||
You can automatically expand properties from the Maven project by using resource filtering.
|
||||
You can automatically expand properties in the Maven project by using resource filtering.
|
||||
If you use the `spring-boot-starter-parent`, you can then refer to your Maven '`project properties`' with `@..@` placeholders, as shown in the following example:
|
||||
|
||||
[source,yaml,indent=0,subs="verbatim",configblocks]
|
||||
@ -126,7 +126,7 @@ Given the examples above, if we have the following configuration:
|
||||
banner-mode: "console"
|
||||
----
|
||||
|
||||
The actual application will show the banner (as overridden by configuration) and uses three sources for the `ApplicationContext`.
|
||||
The actual application will show the banner (as overridden by configuration) and use three sources for the `ApplicationContext`.
|
||||
The application sources are:
|
||||
|
||||
. `MyApplication` (from the code)
|
||||
@ -146,7 +146,7 @@ You can also provide the following System properties (or environment variables)
|
||||
A separate `Environment` property source is set up for this document and it can be overridden by system properties, environment variables, or the command line.
|
||||
|
||||
No matter what you set in the environment, Spring Boot always loads `application.properties` as described above.
|
||||
By default, if YAML is used, then files with the '`.yaml`' and '`.yml`' extension are also added to the list.
|
||||
By default, if YAML is used, then files with the '`.yaml`' and '`.yml`' extensions are also added to the list.
|
||||
|
||||
TIP: If you want detailed information about the files that are being loaded you can <<features#features.logging.log-levels, set the logging level>> of `org.springframework.boot.context.config` to `trace`.
|
||||
|
||||
@ -167,7 +167,7 @@ TIP: If you inherit from the `spring-boot-starter-parent` POM, the default filte
|
||||
If you have enabled Maven filtering for the `application.properties` directly, you may want to also change the default filter token to use https://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#delimiters[other delimiters].
|
||||
|
||||
NOTE: In this specific case, the port binding works in a PaaS environment such as Heroku or Cloud Foundry.
|
||||
In those two platforms, the `PORT` environment variable is set automatically and Spring can bind to capitalized synonyms for `Environment` properties.
|
||||
On those two platforms, the `PORT` environment variable is set automatically and Spring can bind to capitalized synonyms for `Environment` properties.
|
||||
|
||||
|
||||
|
||||
|
@ -135,7 +135,7 @@ It has some useful methods to access the default and user-enhanced message conve
|
||||
|
||||
As in normal MVC usage, any `WebMvcConfigurer` beans that you provide can also contribute converters by overriding the `configureMessageConverters` method.
|
||||
However, unlike with normal MVC, you can supply only additional converters that you need (because Spring Boot uses the same mechanism to contribute its defaults).
|
||||
Finally, if you opt out of the Spring Boot default MVC configuration by providing your own `@EnableWebMvc` configuration, you can take control completely and do everything manually by using `getMessageConverters` from `WebMvcConfigurationSupport`.
|
||||
Finally, if you opt out of the default Spring Boot MVC configuration by providing your own `@EnableWebMvc` configuration, you can take control completely and do everything manually by using `getMessageConverters` from `WebMvcConfigurationSupport`.
|
||||
|
||||
See the {spring-boot-autoconfigure-module-code}/web/servlet/WebMvcAutoConfiguration.java[`WebMvcAutoConfiguration`] source code for more details.
|
||||
|
||||
@ -152,7 +152,7 @@ The multipart support is helpful when you want to receive multipart encoded file
|
||||
|
||||
See the {spring-boot-autoconfigure-module-code}/web/servlet/MultipartAutoConfiguration.java[`MultipartAutoConfiguration`] source for more details.
|
||||
|
||||
NOTE: It is recommended to use the container's built-in support for multipart uploads rather than introducing an additional dependency such as Apache Commons File Upload.
|
||||
NOTE: It is recommended to use the container's built-in support for multipart uploads rather than introduce an additional dependency such as Apache Commons File Upload.
|
||||
|
||||
|
||||
|
||||
|
@ -46,6 +46,6 @@ include::{docs-java}/howto/testing/slicetests/MySecurityConfiguration.java[]
|
||||
include::{docs-java}/howto/testing/slicetests/MyDatasourceConfiguration.java[]
|
||||
----
|
||||
|
||||
Having a single configuration class can be inefficient when beans of a certain domain need to be included in slice tests.
|
||||
Having a single configuration class can be inefficient when beans from a certain domain need to be included in slice tests.
|
||||
Instead, structuring the application's configuration as multiple granular classes with beans for a specific domain can enable importing them only for specific slice tests.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user