diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index ff6224fa812b..6ef28b12413f 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,6 +60,9 @@ * Checkstyle}, {@link TestFailuresPlugin Test Failures}, and {@link TestRetryPlugin Test * Retry} plugins are applied *
  • {@link Test} tasks are configured to use JUnit Platform and use a max heap of 1024M + *
  • A {@code testRuntimeOnly} dependency upon + * {@code org.junit.platform:junit-platform-launcher} is added to projects with the + * {@link JavaPlugin} applied *
  • {@link JavaCompile}, {@link Javadoc}, and {@link FormatTask} tasks are configured * to use UTF-8 encoding *
  • {@link JavaCompile} tasks are configured to use {@code -parameters} and, when @@ -146,6 +149,8 @@ private void configureTestConventions(Project project) { test.useJUnitPlatform(); test.setMaxHeapSize("1024M"); }); + project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies() + .add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher")); project.getPlugins().apply(TestRetryPlugin.class); project.getTasks().withType(Test.class, (test) -> project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28ff446a2157..2a563242c113 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index 6caf0d42f19e..3c3e3a2985d7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -143,7 +143,6 @@ dependencies { testImplementation("org.springframework.security:spring-security-test") testImplementation("org.yaml:snakeyaml") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.springframework.security:spring-security-oauth2-jose") testRuntimeOnly("org.springframework.security:spring-security-oauth2-resource-server") testRuntimeOnly("org.springframework.security:spring-security-saml2-service-provider") diff --git a/spring-boot-project/spring-boot-actuator/build.gradle b/spring-boot-project/spring-boot-actuator/build.gradle index 9135e4235f32..6f0b2d8382bd 100644 --- a/spring-boot-project/spring-boot-actuator/build.gradle +++ b/spring-boot-project/spring-boot-actuator/build.gradle @@ -90,6 +90,5 @@ dependencies { testRuntimeOnly("javax.xml.bind:jaxb-api") testRuntimeOnly("org.apache.tomcat.embed:tomcat-embed-el") testRuntimeOnly("org.glassfish.jersey.ext:jersey-spring5") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.hsqldb:hsqldb") } diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index 6cc40d56349e..86b8b64f4ca6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -185,5 +185,4 @@ dependencies { testImplementation("org.yaml:snakeyaml") testRuntimeOnly("org.jetbrains.kotlin:kotlin-reflect") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-cli/build.gradle b/spring-boot-project/spring-boot-cli/build.gradle index a8007fb6e9a6..c0698c38cd50 100644 --- a/spring-boot-project/spring-boot-cli/build.gradle +++ b/spring-boot-project/spring-boot-cli/build.gradle @@ -66,8 +66,6 @@ dependencies { testImplementation("org.mockito:mockito-junit-jupiter") testImplementation("org.springframework:spring-test") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-amqp", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-aop", configuration: "mavenRepository")) diff --git a/spring-boot-project/spring-boot-devtools/build.gradle b/spring-boot-project/spring-boot-devtools/build.gradle index 3c1d96e2fabf..d4a315540bd8 100644 --- a/spring-boot-project/spring-boot-devtools/build.gradle +++ b/spring-boot-project/spring-boot-devtools/build.gradle @@ -70,7 +70,6 @@ dependencies { testImplementation("org.thymeleaf:thymeleaf-spring5") testImplementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.yaml:snakeyaml") } diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 64d0d2a8a1b6..fa4dcb6ec90c 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -69,19 +69,24 @@ dependencies { implementation(project(path: ":spring-boot-project:spring-boot-autoconfigure")) implementation(project(path: ":spring-boot-project:spring-boot-test")) implementation(project(path: ":spring-boot-project:spring-boot-test-autoconfigure")) + implementation("ch.qos.logback:logback-classic") implementation("com.zaxxer:HikariCP") implementation("io.micrometer:micrometer-core") implementation("io.projectreactor.netty:reactor-netty-http") implementation("io.undertow:undertow-core") + implementation("jakarta.annotation:jakarta.annotation-api") implementation("jakarta.servlet:jakarta.servlet-api") implementation("org.apache.commons:commons-dbcp2") implementation("org.apache.kafka:kafka-streams") + implementation("org.apache.logging.log4j:log4j-to-slf4j") implementation("org.apache.tomcat.embed:tomcat-embed-core") implementation("org.assertj:assertj-core") implementation("org.glassfish.jersey.core:jersey-server") implementation("org.hibernate:hibernate-jcache") + implementation("org.slf4j:jul-to-slf4j") implementation("org.springframework:spring-test") implementation("org.springframework:spring-web") + implementation("org.springframework:spring-webmvc") implementation("org.springframework:spring-webflux") implementation("org.springframework.data:spring-data-couchbase") implementation("org.springframework.data:spring-data-neo4j") @@ -93,6 +98,7 @@ dependencies { implementation("org.springframework.security:spring-security-config") implementation("org.springframework.security:spring-security-web") implementation("org.junit.jupiter:junit-jupiter") + implementation("org.yaml:snakeyaml") mavenPluginDocumentation(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin", configuration: "documentation")) @@ -103,7 +109,6 @@ dependencies { testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testRuntimeOnly("com.h2database:h2") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.springframework:spring-jdbc") testSlices(project(path: ":spring-boot-project:spring-boot-test-autoconfigure", configuration: "testSliceMetadata")) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-configuration-metadata.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-configuration-metadata.adoc index 0fbf46396881..0a8fa6f48722 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-configuration-metadata.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-configuration-metadata.adoc @@ -220,7 +220,7 @@ Deprecation can also be specified declaratively in code by adding the `@Deprecat For instance, assume that the `app.acme.target` property was confusing and was renamed to `app.acme.name`. The following example shows how to handle that situation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @ConfigurationProperties("app.acme") public class AcmeProperties { @@ -343,7 +343,7 @@ The special `.keys` and `.values` suffixes must refer to the keys and the values Assume a `sample.contexts` maps magic `String` values to an integer, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @ConfigurationProperties("sample") public class SampleProperties { @@ -762,7 +762,7 @@ The annotation processor also supports the use of the `@Data`, `@Getter`, and `@ Consider the following example: -[source,java,indent=0,subs="verbatim,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,attributes"] ---- @ConfigurationProperties(prefix="server") public class ServerProperties { @@ -799,7 +799,7 @@ Also, the annotation processor cannot auto-detect default values for ``Enum``s a For cases where the default value could not be detected, <> should be provided. Consider the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @ConfigurationProperties(prefix = "acme.messaging") public class MessagingProperties { @@ -845,7 +845,7 @@ The annotation processor automatically considers inner classes as nested propert Rather than documenting the `ip` and `port` at the root of the namespace, we could create a sub-namespace for it. Consider the updated example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @ConfigurationProperties(prefix="server") public class ServerProperties { diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/attributes.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/attributes.adoc index ba0c8bc45ee8..ea14af6df87e 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/attributes.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/attributes.adoc @@ -20,8 +20,10 @@ :github-issues: https://github.com/{github-repo}/issues/ :github-wiki: https://github.com/{github-repo}/wiki -:code-examples: ../main/java/org/springframework/boot/docs -:test-examples: ../test/java/org/springframework/boot/docs +:include: ../main/java/org/springframework/boot/docs +:include-springbootfeatures: {include}/springbootfeatures +:include-productionreadyfeatures: {include}/productionreadyfeatures +:include-howto: {include}/howto :spring-boot-code: https://github.com/{github-repo}/tree/{github-tag} :spring-boot-api: https://docs.spring.io/spring-boot/docs/{spring-boot-version}/api @@ -94,9 +96,6 @@ :spring-session: https://spring.io/projects/spring-session :spring-webservices-docs: https://docs.spring.io/spring-ws/docs/{spring-webservices-version}/reference/ - - - :ant-docs: https://ant.apache.org/manual :dependency-management-plugin-code: https://github.com/spring-gradle-plugins/dependency-management-plugin :gradle-docs: https://docs.gradle.org/current/userguide diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins.adoc index 9cb3488060ea..2b086d1dc341 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins.adoc @@ -223,7 +223,7 @@ An exception is thrown if more than one candidate is found. === Example Repackage Implementation The following example shows a typical repackage implementation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- Repackager repackager = new Repackager(sourceJarFile); repackager.setBackupSource(false); diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc index 8a42e7eb9eff..d6879eee5ac0 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc @@ -135,7 +135,7 @@ Process-scoped environment variables are language agnostic. Environment variables do not always make for the easiest API, so Spring Boot automatically extracts them and flattens the data into properties that can be accessed through Spring's `Environment` abstraction, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component class MyBean implements EnvironmentAware { diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started.adoc index d359898a112b..b030d52e22db 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started.adoc @@ -483,7 +483,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a To finish our application, we need to create a single Java file. By default, Maven compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/Example.java` to contain the following code: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc index becead5f7734..481c0762e21f 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc @@ -95,7 +95,7 @@ For instance, the following example loads a YAML configuration file from the cla [source,java,indent=0] ---- -include::{code-examples}/context/EnvironmentPostProcessorExample.java[tag=example] +include::{include-howto}/springbootapplication/MyEnvironmentPostProcessor.java[tag=*] ---- TIP: The `Environment` has already been prepared with all the usual property sources that Spring Boot loads by default. @@ -239,7 +239,7 @@ Then the Spring Boot banner is not printed on startup, and the application is no Properties defined in external configuration override the values specified with the Java API, with the notable exception of the sources used to create the `ApplicationContext`. Consider the following application: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- new SpringApplicationBuilder() .bannerMode(Banner.Mode.OFF) @@ -513,7 +513,7 @@ The best way to get that and be sure it has been initialized is to add a `@Bean` Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can also inject the actual port into a field by using the `@LocalServerPort` annotation, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) public class MyWebIntegrationTests { @@ -658,7 +658,7 @@ and instead apply a customizer specific to your choice of server: For Tomcat, we need to add an upgrade protocol: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public TomcatConnectorCustomizer connectorCustomizer() { @@ -668,7 +668,7 @@ For Tomcat, we need to add an upgrade protocol: For Jetty, we need to add a connection factory to the existing connector: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public JettyServerCustomizer serverCustomizer() { @@ -687,7 +687,7 @@ For Jetty, we need to add a connection factory to the existing connector: For Netty, we need to add `h2c` as a supported protocol: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public NettyServerCustomizer serverCustomizer() { @@ -697,7 +697,7 @@ For Netty, we need to add `h2c` as a supported protocol: For Undertow, we need to enable the HTTP2 option: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public UndertowBuilderCustomizer builderCustomizer() { @@ -721,7 +721,7 @@ You can declare such a component and get access to the server factory relevant t The example below is for Tomcat with the `spring-boot-starter-web` (Servlet stack): -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Component public class MyTomcatWebServerCustomizer @@ -802,7 +802,7 @@ Like any other Spring bean, you can define the order of Servlet filter beans; pl As <>, any `Servlet` or `Filter` beans are registered with the servlet container automatically. To disable registration of a particular `Filter` or `Servlet` bean, create a registration bean for it and mark it as disabled, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public FilterRegistrationBean registration(MyFilter filter) { @@ -931,7 +931,7 @@ You can add an `org.apache.catalina.connector.Connector` to the `TomcatServletWe [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/context/embedded/TomcatMultipleConnectorsExample.java[tag=configuration] +include::{include-howto}/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java[tag=*] ---- @@ -951,7 +951,7 @@ To switch to the `LegacyCookieProcessor`, use an `WebServerFactoryCustomizer` be [source,java,indent=0] ---- -include::{code-examples}/context/embedded/TomcatLegacyCookieProcessorExample.java[tag=customizer] +include::{include-howto}/embeddedwebservers/LegacyCookieProcessorConfiguration.java[tag=*] ---- @@ -978,7 +978,7 @@ Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/context/embedded/UndertowMultipleListenersExample.java[tag=configuration] +include::{include-howto}/embeddedwebservers/UndertowMultipleListenersConfiguration.java[tag=*] ---- @@ -987,7 +987,7 @@ include::{code-examples}/context/embedded/UndertowMultipleListenersExample.java[ === Create WebSocket Endpoints Using @ServerEndpoint If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded container, you must declare a single `ServerEndpointExporter` `@Bean`, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public ServerEndpointExporter serverEndpointExporter() { @@ -1012,7 +1012,7 @@ This section answers common questions about Spring MVC and Spring Boot. === Write a JSON REST Service Any Spring `@RestController` in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @RestController public class MyController { @@ -1046,7 +1046,7 @@ To use the Jackson XML renderer, add the following dependency to your project: If Jackson's XML extension is not available and JAXB is available, XML can be rendered with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @XmlRootElement public class MyThing { @@ -1251,7 +1251,7 @@ For more detail, see the following sections: Spring Security provides support for running tests as a specific user. For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role. -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Test @WithMockUser(roles="ADMIN") @@ -1283,7 +1283,7 @@ The `jersey.config.server.response.setStatusOverSendError` property must be set [source,java,indent=0] ---- -include::{code-examples}/jersey/JerseySetStatusOverSendErrorExample.java[tag=resource-config] +include::{include-howto}/jersey/JerseySetStatusOverSendErrorConfig.java[tag=*] ---- @@ -1294,7 +1294,7 @@ To use Jersey alongside another web framework, such as Spring MVC, it should be First, configure Jersey to use a Filter rather than a Servlet by configuring the configprop:spring.jersey.type[] application property with a value of `filter`. Second, configure your `ResourceConfig` to forward requests that would have resulted in a 404, as shown in the following example. -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Component public class JerseyConfig extends ResourceConfig { @@ -1326,7 +1326,7 @@ The following example configures `HttpComponentsClientRequestFactory` with an `H [source,java,indent=0] ---- -include::{code-examples}/web/client/RestTemplateProxyCustomizationExample.java[tag=customizer] +include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizer.java[tag=*] ---- [[howto-webclient-reactor-netty-customization]] @@ -1337,7 +1337,7 @@ The following example configures a 60 second connect timeout and adds a `ReadTim [source,java,indent=0] ---- -include::{code-examples}/web/reactive/function/client/ReactorNettyClientCustomizationExample.java[tag=custom-http-connector] +include::{include-howto}/httpclients/CustomizeReactorNettyClientConfiguration.java[tag=*] ---- TIP: Note the use of `ReactorResourceFactory` for the connection provider and event loop resources. @@ -1551,7 +1551,7 @@ If you need to externalize some settings, you can bind your `DataSource` to the The following example shows how to define a data source in a bean: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean @ConfigurationProperties(prefix="app.datasource") @@ -1582,7 +1582,7 @@ The following example shows how to create a data source by using a `DataSourceBu [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/jdbc/BasicDataSourceExample.java[tag=configuration] +include::{include-howto}/dataaccess/BasicDataSourceConfiguration.java[tag=*] ---- To run an app with that `DataSource`, all you need is the connection information. @@ -1623,7 +1623,7 @@ The following example shows how create a `HikariDataSource` with `DataSourceBuil [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/jdbc/SimpleDataSourceExample.java[tag=configuration] +include::{include-howto}/dataaccess/SimpleDataSourceConfiguration.java[tag=*] ---- You can even go further by leveraging what `DataSourceProperties` does for you -- that is, by providing a default embedded database with a sensible username and password if no URL is provided. @@ -1633,7 +1633,7 @@ To avoid that, you can redefine a custom `DataSourceProperties` on your custom n [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/jdbc/ConfigurableDataSourceExample.java[tag=configuration] +include::{include-howto}/dataaccess/ConfigurableDataSourceConfiguration.java[tag=*] ---- This setup puts you _in sync_ with what Spring Boot does for you by default, except that a dedicated connection pool is chosen (in code) and its settings are exposed in the `app.datasource.configuration` sub namespace. @@ -1670,7 +1670,7 @@ In the following example, we provide the _exact_ same feature set as the auto-co [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/jdbc/SimpleTwoDataSourcesExample.java[tag=configuration] +include::{include-howto}/dataaccess/SimpleDataSourcesConfiguration.java[tag=*] ---- TIP: `firstDataSourceProperties` has to be flagged as `@Primary` so that the database initializer feature uses your copy (if you use the initializer). @@ -1700,7 +1700,7 @@ You can apply the same concept to the secondary `DataSource` as well, as shown i [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/jdbc/CompleteTwoDataSourcesExample.java[tag=configuration] +include::{include-howto}/dataaccess/CompleteDataSourcesConfiguration.java[tag=*] ---- The preceding example configures two data sources on custom namespaces with the same logic as Spring Boot would use in auto-configuration. @@ -1729,7 +1729,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page]. Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds. To get more control, you can use the `@EntityScan` annotation, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Configuration(proxyBeanMethods = false) @EnableAutoConfiguration @@ -1794,7 +1794,7 @@ This implementation provides the same table structure as Hibernate 4: all dots a [source,java,indent=0] ---- -include::{code-examples}/jpa/CaseSensitiveSpringPhysicalNamingStrategyExample.java[tag=naming-strategy] +include::{include-howto}/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java[tag=*] ---- If you prefer to use Hibernate 5's default instead, set the following property: @@ -1806,7 +1806,7 @@ If you prefer to use Hibernate 5's default instead, set the following property: Alternatively, you can configure the following bean: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public PhysicalNamingStrategy physicalNamingStrategy() { @@ -1828,7 +1828,7 @@ Then, add a `HibernatePropertiesCustomizer` bean as shown in the following examp [source,java,indent=0] ---- -include::{code-examples}/jpa/HibernateSecondLevelCacheExample.java[tag=configuration] +include::{include-howto}/dataaccess/HibernateSecondLevelCacheConfiguration.java[tag=*] ---- This customizer will configure Hibernate to use the same `CacheManager` as the one that the application uses. @@ -1858,7 +1858,7 @@ Even if the default `EntityManagerFactory` works fine, you need to define a new You can use the `EntityManagerBuilder` provided by Spring Boot to help you to create one. Alternatively, you can use the `LocalContainerEntityManagerFactoryBean` directly from Spring ORM, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- // add two data sources configured as above @@ -1896,7 +1896,7 @@ Alternatively, you might be able to use a JTA transaction manager that spans bot If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Configuration(proxyBeanMethods = false) @EnableJpaRepositories(basePackageClasses = Customer.class, @@ -1969,7 +1969,7 @@ For example, if you use Hibernate Search with Elasticsearch as its index manager [source,java,indent=0] ---- -include::{code-examples}/elasticsearch/HibernateSearchElasticsearchExample.java[tag=configuration] +include::{include-howto}/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java[tag=*] ---- @@ -2066,7 +2066,7 @@ You can initialize the database on startup using SQL scripts as shown in the fol [source,java,indent=0] ---- -include::{code-examples}/r2dbc/R2dbcDatabaseInitializationExample.java[tag=configuration] +include::{include-howto}/dataaccess/R2dbcDatabaseInitializationConfiguration.java[tag=*] ---- Alternatively, you can configure either <> or <> to configure a `DataSource` for you for the duration of the migration. @@ -2206,7 +2206,7 @@ If your JMS broker does not support transacted sessions, you have to disable the If you create your own `JmsListenerContainerFactory`, there is nothing to do, since, by default it cannot be transacted. If you want to use the `DefaultJmsListenerContainerFactoryConfigurer` to reuse Spring Boot's default, you can disable transacted sessions, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean public DefaultJmsListenerContainerFactory jmsListenerContainerFactory( @@ -2351,7 +2351,7 @@ The following example shows one way to write such an exporter: [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/actuate/metrics/MetricsHealthMicrometerExportExample.java[tag=configuration] +include::{include-howto}/actuator/MetricsHealthMicrometerExport.java[tag=*] ---- @@ -2399,7 +2399,7 @@ Alternatively, you can add the `RemoteIpValve` by customizing the `TomcatServlet To configure Spring Security to require a secure channel for all (or some) requests, consider adding your own `SecurityFilterChain` bean that adds the following `HttpSecurity` configuration: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -2798,7 +2798,7 @@ The first step in producing a deployable war file is to provide a `SpringBootSer Doing so makes use of Spring Framework's Servlet 3.0 support and lets you configure your application when it is launched by the servlet container. Typically, you should update your application's main class to extend `SpringBootServletInitializer`, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootApplication public class Application extends SpringBootServletInitializer { @@ -2875,7 +2875,7 @@ See the https://spring.io/guides/gs/convert-jar-to-war/[Getting Started Guide on To create a deployable war by extending `SpringBootServletInitializer` (for example, in a class called `Application`) and adding the Spring Boot `@SpringBootApplication` annotation, use code similar to that shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootApplication public class Application extends SpringBootServletInitializer { @@ -2908,7 +2908,7 @@ If you have other features in your application (for instance, using other servle Once the war file is working, you can make it executable by adding a `main` method to your `Application`, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- public static void main(String[] args) { SpringApplication.run(Application.class, args); @@ -2919,7 +2919,7 @@ Once the war file is working, you can make it executable by adding a `main` meth ==== If you intend to start your application as a war or as an executable application, you need to share the customizations of the builder in a method that is both available to the `SpringBootServletInitializer` callback and in the `main` method in a class similar to the following: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootApplication public class Application extends SpringBootServletInitializer { @@ -2969,7 +2969,7 @@ To deploy a Spring Boot application to WebLogic, you must ensure that your servl A typical initializer for WebLogic should resemble the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @@ -3052,7 +3052,7 @@ It integrates with JUnit, allowing you to write a test class that can start up a Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc. Testcontainers can be used in a Spring Boot test as follows: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootTest @Testcontainers @@ -3069,7 +3069,7 @@ In most cases, you will need to configure the application using details from the This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment. -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @SpringBootTest @Testcontainers diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc index eb4cce878a9c..e3fd322882ab 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc @@ -357,7 +357,7 @@ If you wish to configure custom security for HTTP endpoints, for example, only a A typical Spring Security configuration might look something like the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -386,7 +386,7 @@ You can do so by changing the configprop:management.endpoints.web.exposure.inclu Additionally, if Spring Security is present, you would need to add custom security configuration that allows unauthenticated access to the endpoints as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -463,7 +463,7 @@ The following example exposes a read operation that returns a custom object: [source,java,indent=0] ---- -include::{code-examples}/actuate/endpoint/CustomEndpointExample.java[tag=read] +include::{include-productionreadyfeatures}/endpoints/CustomEndpoint.java[tag=read] ---- You can also write technology-specific endpoints by using `@JmxEndpoint` or `@WebEndpoint`. @@ -500,7 +500,7 @@ This can be used to invoke a write operation that takes `String name` and `int c [source,java,indent=0] ---- -include::{code-examples}/actuate/endpoint/CustomEndpointExample.java[tag=write] +include::{include-productionreadyfeatures}/endpoints/CustomEndpoint.java[tag=write] ---- TIP: Because endpoints are technology agnostic, only simple types can be specified in the method signature. @@ -776,7 +776,7 @@ You need to provide an implementation of the `health()` method and return a `Hea The `Health` response should include a status and can optionally include additional details to be displayed. The following code shows a sample `HealthIndicator` implementation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; @@ -870,7 +870,7 @@ If you need to register a regular `HealthContributor`, you should wrap it using To provide custom health information from a reactive API, you can register Spring beans that implement the {spring-boot-actuator-module-code}/health/ReactiveHealthIndicator.java[`ReactiveHealthIndicator`] interface. The following code shows a sample `ReactiveHealthIndicator` implementation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class MyReactiveHealthIndicator implements ReactiveHealthIndicator { @@ -1226,7 +1226,7 @@ To provide custom application information, you can register Spring beans that im The following example contributes an `example` entry with a single value: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import java.util.Collections; @@ -1612,7 +1612,7 @@ Spring Boot will also add any auto-configured registries to the global static co You can register any number of `MeterRegistryCustomizer` beans to further configure the registry, such as applying common tags, before any meters are registered with the registry: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean MeterRegistryCustomizer metricsCommonTags() { @@ -1622,7 +1622,7 @@ You can register any number of `MeterRegistryCustomizer` beans to further config You can apply customizations to particular registry implementations by being more specific about the generic type: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean MeterRegistryCustomizer graphiteMetricsNamingConvention() { @@ -1780,12 +1780,12 @@ Micrometer provides a default `HierarchicalNameMapper` that governs how a dimens TIP: To take control over this behaviour, define your `GraphiteMeterRegistry` and supply your own `HierarchicalNameMapper`. An auto-configured `GraphiteConfig` and `Clock` beans are provided unless you define your own: -[source,java] +[source,java,pending-extract=true,indent=0] ---- -@Bean -public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { - return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); -} + @Bean + public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { + return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); + } ---- @@ -1855,12 +1855,12 @@ Micrometer provides a default `HierarchicalNameMapper` that governs how a dimens TIP: To take control over this behaviour, define your `JmxMeterRegistry` and supply your own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are provided unless you define your own: -[source,java] +[source,java,pending-extract=true,indent=0] ---- -@Bean -public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { - return new JmxMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); -} + @Bean + public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { + return new JmxMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); + } ---- @@ -2128,7 +2128,7 @@ Auto-configuration enables the instrumentation of requests handled by Spring MVC When `management.metrics.web.server.request.autotime.enabled` is `true`, this instrumentation occurs for all requests. Alternatively, when set to `false`, you can enable instrumentation by adding `@Timed` to a request-handling method: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @RestController @Timed <1> @@ -2217,7 +2217,7 @@ When Micrometer's `micrometer-jersey2` module is on the classpath, auto-configur When `management.metrics.web.server.request.autotime.enabled` is `true`, this instrumentation occurs for all requests. Alternatively, when set to `false`, you can enable instrumentation by adding `@Timed` to a request-handling method: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component @Path("/api/people") @@ -2379,14 +2379,14 @@ To register custom metrics, inject `MeterRegistry` into your component, as shown [source,java,indent=0] ---- -include::{code-examples}/actuate/metrics/MetricsMeterRegistryInjectionExample.java[tag=component] +include::{include-productionreadyfeatures}/metrics/MetricsMeterRegistryInjection.java[tag=*] ---- If your metrics depend on other beans, it is recommended that you use a `MeterBinder` to register them, as shown in the following example: [source,java,indent=0] ---- -include::{code-examples}/actuate/metrics/SampleMeterBinderConfiguration.java[tag=example] +include::{include-productionreadyfeatures}/metrics/SampleMeterBinderConfiguration.java[tag=*] ---- Using a `MeterBinder` ensures that the correct dependency relationships are set up and that the bean is available when the metric's value is retrieved. @@ -2404,7 +2404,7 @@ For example, if you want to rename the `mytag.region` tag to `mytag.area` for al [source,java,indent=0] ---- -include::{code-examples}/actuate/metrics/MetricsFilterBeanExample.java[tag=configuration] +include::{include-productionreadyfeatures}/metrics/MetricsFilterConfiguration.java[tag=*] ---- @@ -2622,7 +2622,7 @@ For Tomcat, the following configuration can be added: [source,java,indent=0] ---- -include::{code-examples}/cloudfoundry/CloudFoundryCustomContextPathExample.java[tag=configuration] +include::{include-productionreadyfeatures}/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java[tag=*] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-cli.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-cli.adoc index 33fbb59ef58d..dfd82eda5e5e 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-cli.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-cli.adoc @@ -209,7 +209,7 @@ The preceding declaration picks up `custom-bom-1.0.0.pom` in a Maven repository When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @DependencyManagementBom(["com.example.custom-bom:1.0.0", "com.example.another-bom:1.0.0"]) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index d39fd0e48c40..b3c6eefe947a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -15,9 +15,7 @@ In many situations, you can delegate to the static `SpringApplication.run` metho [source,java,indent=0] ---- - public static void main(String[] args) { - SpringApplication.run(MySpringConfiguration.class, args); - } +include::{include-springbootfeatures}/springapplication/main/run/MyApplication.java[tag=*] ---- When your application starts, you should see something similar to the following output: @@ -32,12 +30,20 @@ When your application starts, you should see something similar to the following =========|_|==============|___/=/_/_/_/ :: Spring Boot :: v{spring-boot-version} -2019-04-31 13:09:54.117 INFO 56603 --- [ main] o.s.b.s.app.SampleApplication : Starting SampleApplication v0.1.0 on mycomputer with PID 56603 (/apps/myapp.jar started by pwebb) -2019-04-31 13:09:54.166 INFO 56603 --- [ main] ationConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e5a8246: startup date [Wed Jul 31 00:08:16 PDT 2013]; root of context hierarchy -2019-04-01 13:09:56.912 INFO 41370 --- [ main] .t.TomcatServletWebServerFactory : Server initialized with port: 8080 -2019-04-01 13:09:57.501 INFO 41370 --- [ main] o.s.b.s.app.SampleApplication : Started SampleApplication in 2.992 seconds (JVM running for 3.658) +2021-02-03 10:33:25.224 INFO 17321 --- [ main] o.s.b.d.s.s.SpringAppplicationExample : Starting SpringAppplicationExample using Java 1.8.0_232 on mycomputer with PID 17321 (/apps/myjar.jar started by pwebb) +2021-02-03 10:33:25.226 INFO 17900 --- [ main] o.s.b.d.s.s.SpringAppplicationExample : No active profile set, falling back to default profiles: default +2021-02-03 10:33:26.046 INFO 17321 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) +2021-02-03 10:33:26.054 INFO 17900 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] +2021-02-03 10:33:26.055 INFO 17900 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41] +2021-02-03 10:33:26.097 INFO 17900 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext +2021-02-03 10:33:26.097 INFO 17900 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 821 ms +2021-02-03 10:33:26.144 INFO 17900 --- [ main] s.tomcat.SampleTomcatApplication : ServletContext initialized +2021-02-03 10:33:26.376 INFO 17900 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' +2021-02-03 10:33:26.384 INFO 17900 --- [ main] o.s.b.d.s.s.SpringAppplicationExample : Started SampleTomcatApplication in 1.514 seconds (JVM running for 1.823) ---- + + By default, `INFO` logging messages are shown, including some relevant startup details, such as the user that launched the application. If you need a log level other than `INFO`, you can set it, as described in <>. The application version is determined using the implementation version from the main application class's package. @@ -170,11 +176,7 @@ For example, to turn off the banner, you could write: [source,java,indent=0] ---- - public static void main(String[] args) { - SpringApplication app = new SpringApplication(MySpringConfiguration.class); - app.setBannerMode(Banner.Mode.OFF); - app.run(args); - } +include::{include-springbootfeatures}/springapplication/main/custom/MyApplication.java[tag=*] ---- NOTE: The constructor arguments passed to `SpringApplication` are configuration sources for Spring beans. @@ -195,7 +197,7 @@ The `SpringApplicationBuilder` lets you chain together multiple method calls and [source,java,indent=0] ---- -include::{code-examples}/builder/SpringApplicationBuilderExample.java[tag=hierarchy] +include::{include-springbootfeatures}/springapplication/SpringApplicationBuilderExample.java[tag=*] ---- NOTE: There are some restrictions when creating an `ApplicationContext` hierarchy. @@ -249,47 +251,14 @@ For example, we can export the "Readiness" state of the application to a file so [source,java,indent=0] ---- - @Component - public class ReadinessStateExporter { - - @EventListener - public void onStateChange(AvailabilityChangeEvent event) { - switch (event.getState()) { - case ACCEPTING_TRAFFIC: - // create file /tmp/healthy - break; - case REFUSING_TRAFFIC: - // remove file /tmp/healthy - break; - } - } - - } +include::{include-springbootfeatures}/springapplication/availability/ReadinessStateExporter.java[tag=*] ---- We can also update the state of the application, when the application breaks and cannot recover: [source,java,indent=0] ---- - @Component - public class LocalCacheVerifier { - - private final ApplicationEventPublisher eventPublisher; - - public LocalCacheVerifier(ApplicationEventPublisher eventPublisher) { - this.eventPublisher = eventPublisher; - } - - public void checkLocalCache() { - try { - //... - } - catch (CacheCompletelyBrokenException ex) { - AvailabilityChangeEvent.publish(this.eventPublisher, ex, LivenessState.BROKEN); - } - } - - } +include::{include-springbootfeatures}/springapplication/availability/LocalCacheVerifier.java[tag=*] ---- Spring Boot provides <>. @@ -374,21 +343,7 @@ The `ApplicationArguments` interface provides access to both the raw `String[]` [source,java,indent=0] ---- - import org.springframework.boot.*; - import org.springframework.beans.factory.annotation.*; - import org.springframework.stereotype.*; - - @Component - public class MyBean { - - @Autowired - public MyBean(ApplicationArguments args) { - boolean debug = args.containsOption("debug"); - List files = args.getNonOptionArgs(); - // if run with "--debug logfile.txt" debug=true, files=["logfile.txt"] - } - - } +include::{include-springbootfeatures}/springapplication/ApplicationArgumentsExample.java[tag=*] ---- TIP: Spring Boot also registers a `CommandLinePropertySource` with the Spring `Environment`. @@ -409,17 +364,7 @@ The following example shows a `CommandLineRunner` with a `run` method: [source,java,indent=0] ---- - import org.springframework.boot.*; - import org.springframework.stereotype.*; - - @Component - public class MyBean implements CommandLineRunner { - - public void run(String... args) { - // Do something... - } - - } +include::{include-springbootfeatures}/springapplication/CommandLineRunnerExample.java[tag=*] ---- If several `CommandLineRunner` or `ApplicationRunner` beans are defined that must be called in a specific order, you can additionally implement the `org.springframework.core.Ordered` interface or use the `org.springframework.core.annotation.Order` annotation. @@ -436,7 +381,7 @@ This exit code can then be passed to `System.exit()` to return it as a status co [source,java,indent=0] ---- -include::{code-examples}/ExitCodeApplication.java[tag=example] +include::{include-springbootfeatures}/springapplication/exitcode/MyApplication.java[tag=*] ---- Also, the `ExitCodeGenerator` interface may be implemented by exceptions. @@ -467,11 +412,7 @@ For example, to use the `BufferingApplicationStartup`, you could write: [source,java,indent=0] ---- - public static void main(String[] args) { - SpringApplication app = new SpringApplication(MySpringConfiguration.class); - app.setApplicationStartup(new BufferingApplicationStartup(2048)); - app.run(args); - } +include::{include-springbootfeatures}/springapplication/startup/MyApplication.java[tag=*] ---- The first available implementation, `FlightRecorderApplicationStartup` is provided by Spring Framework. @@ -526,18 +467,7 @@ To provide a concrete example, suppose you develop a `@Component` that uses a `n [source,java,indent=0] ---- - import org.springframework.stereotype.*; - import org.springframework.beans.factory.annotation.*; - - @Component - public class MyBean { - - @Value("${name}") - private String name; - - // ... - - } +include::{include-springbootfeatures}/externalizedconfiguration/valueinjection/MyBean.java[tag=*] ---- On your application classpath (for example, inside your jar) you can have an `application.properties` file that provides a sensible default property value for `name`. @@ -597,7 +527,7 @@ This means that the JSON cannot override properties from lower order property so [[boot-features-external-config-files]] -=== External Application Properties [[boot-features-external-config-application-property-files]] +=== External Application Properties [[boot-features-external-config-application-property-files]] Spring Boot will automatically find and load `application.properties` and `application.yaml` files from the following locations when your application starts: . The classpath root @@ -1109,56 +1039,7 @@ It is possible to bind a bean declaring standard JavaBean properties as shown in [source,java,indent=0] ---- - package com.example; - - import java.net.InetAddress; - import java.util.ArrayList; - import java.util.Collections; - import java.util.List; - - import org.springframework.boot.context.properties.ConfigurationProperties; - - @ConfigurationProperties("acme") - public class AcmeProperties { - - private boolean enabled; - - private InetAddress remoteAddress; - - private final Security security = new Security(); - - public boolean isEnabled() { ... } - - public void setEnabled(boolean enabled) { ... } - - public InetAddress getRemoteAddress() { ... } - - public void setRemoteAddress(InetAddress remoteAddress) { ... } - - public Security getSecurity() { ... } - - public static class Security { - - private String username; - - private String password; - - private List roles = new ArrayList<>(Collections.singleton("USER")); - - public String getUsername() { ... } - - public void setUsername(String username) { ... } - - public String getPassword() { ... } - - public void setPassword(String password) { ... } - - public List getRoles() { ... } - - public void setRoles(List roles) { ... } - - } - } +include::{include-springbootfeatures}/externalizedconfiguration/javabeanbinding/AcmeProperties.java[tag=*] ---- The preceding POJO defines the following properties: @@ -1199,61 +1080,7 @@ The example in the previous section can be rewritten in an immutable fashion as [source,java,indent=0] ---- - package com.example; - - import java.net.InetAddress; - import java.util.List; - - import org.springframework.boot.context.properties.ConfigurationProperties; - import org.springframework.boot.context.properties.ConstructorBinding; - import org.springframework.boot.context.properties.bind.DefaultValue; - - @ConstructorBinding - @ConfigurationProperties("acme") - public class AcmeProperties { - - private final boolean enabled; - - private final InetAddress remoteAddress; - - private final Security security; - - public AcmeProperties(boolean enabled, InetAddress remoteAddress, Security security) { - this.enabled = enabled; - this.remoteAddress = remoteAddress; - this.security = security; - } - - public boolean isEnabled() { ... } - - public InetAddress getRemoteAddress() { ... } - - public Security getSecurity() { ... } - - public static class Security { - - private final String username; - - private final String password; - - private final List roles; - - public Security(String username, String password, - @DefaultValue("USER") List roles) { - this.username = username; - this.password = password; - this.roles = roles; - } - - public String getUsername() { ... } - - public String getPassword() { ... } - - public List getRoles() { ... } - - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/constructorbinding/AcmeProperties.java[tag=*] ---- In this setup, the `@ConstructorBinding` annotation is used to indicate that constructor binding should be used. @@ -1267,30 +1094,7 @@ If you wish you return a non-null instance of `Security` even when no properties [source,java,indent=0] ---- - package com.example; - import java.net.InetAddress; - import java.util.List; - - import org.springframework.boot.context.properties.ConfigurationProperties; - import org.springframework.boot.context.properties.ConstructorBinding; - import org.springframework.boot.context.properties.bind.DefaultValue; - - @ConstructorBinding - @ConfigurationProperties("acme") - public class AcmeProperties { - - private final boolean enabled; - - private final InetAddress remoteAddress; - - private final Security security; - - public AcmeProperties(boolean enabled, InetAddress remoteAddress, @DefaultValue Security security) { - this.enabled = enabled; - this.remoteAddress = remoteAddress; - this.security = security; - } - } +include::{include-springbootfeatures}/externalizedconfiguration/constructorbinding/nonnull/AcmeProperties.java[tag=*] ---- @@ -1316,10 +1120,7 @@ This can be done on any `@Configuration` class, as shown in the following exampl [source,java,indent=0] ---- - @Configuration(proxyBeanMethods = false) - @EnableConfigurationProperties(AcmeProperties.class) - public class MyConfiguration { - } +include::{include-springbootfeatures}/externalizedconfiguration/enable/MyConfiguration.java[tag=*] ---- To use configuration property scanning, add the `@ConfigurationPropertiesScan` annotation to your application. @@ -1329,10 +1130,7 @@ If you want to define specific packages to scan, you can do so as shown in the f [source,java,indent=0] ---- - @SpringBootApplication - @ConfigurationPropertiesScan({ "com.example.app", "org.acme.another" }) - public class MyApplication { - } +include::{include-springbootfeatures}/externalizedconfiguration/enable/MyApplication.java[tag=*] ---- [NOTE] @@ -1368,25 +1166,7 @@ To work with `@ConfigurationProperties` beans, you can inject them in the same w [source,java,indent=0] ---- - @Service - public class MyService { - - private final AcmeProperties properties; - - @Autowired - public MyService(AcmeProperties properties) { - this.properties = properties; - } - - //... - - @PostConstruct - public void openConnection() { - Server server = new Server(this.properties.getRemoteAddress()); - // ... - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/use/MyService.java[tag=*] ---- TIP: Using `@ConfigurationProperties` also lets you generate metadata files that can be used by IDEs to offer auto-completion for your own keys. @@ -1403,11 +1183,7 @@ To configure a bean from the `Environment` properties, add `@ConfigurationProper [source,java,indent=0] ---- - @ConfigurationProperties(prefix = "another") - @Bean - public AnotherComponent anotherComponent() { - ... - } +include::{include-springbootfeatures}/externalizedconfiguration/ThirdPartyConfiguration.java[tag=*] ---- Any JavaBean property defined with the `another` prefix is mapped onto that `AnotherComponent` bean in manner similar to the preceding `AcmeProperties` example. @@ -1423,20 +1199,7 @@ As an example, consider the following `@ConfigurationProperties` class: [source,java,indent=0] ---- - @ConfigurationProperties(prefix="acme.my-project.person") - public class OwnerProperties { - - private String firstName; - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/relaxed/OwnerProperties.java[tag=*] ---- With the preceding code, the following properties names can all be used: @@ -1519,7 +1282,7 @@ The properties above will bind to a `Map` with `/key1`, `/key2` and `key3` as th The slash has been removed from `key3` because it wasn't surrounded by square brackets. You may also occasionally need to use the bracket notation if your `key` contains a `.` and you are binding to non-scalar value. -For example, binding `a.b=c` to `Map` will return a Map with the entry `{"a"={"b"="c"}}` where as `[a.b]=c` will return a Map with the entry `{"a.b"="c"}`. +For example, binding `a.b=c` to `Map` will return a Map with the entry `{"a"={"b"="c"}}` where as `[a.b]=c` will return a Map with the entry `{"a.b"="c"}`. @@ -1555,16 +1318,7 @@ The following example exposes a list of `MyPojo` objects from `AcmeProperties`: [source,java,indent=0] ---- - @ConfigurationProperties("acme") - public class AcmeProperties { - - private final List list = new ArrayList<>(); - - public List getList() { - return this.list; - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/merge/list/AcmeProperties.java[tag=*] ---- Consider the following configuration: @@ -1619,16 +1373,7 @@ The following example exposes a `Map` from `AcmeProperties`: [source,java,indent=0] ---- - @ConfigurationProperties("acme") - public class AcmeProperties { - - private final Map map = new HashMap<>(); - - public Map getMap() { - return this.map; - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/merge/map/AcmeProperties.java[tag=*] ---- Consider the following configuration: @@ -1673,7 +1418,7 @@ You may want to rename your custom `ConversionService` if it is not required for [[boot-features-external-config-conversion-duration]] -===== Converting durations +===== Converting Durations Spring Boot has dedicated support for expressing durations. If you expose a `java.time.Duration` property, the following formats in application properties are available: @@ -1685,7 +1430,7 @@ Consider the following example: [source,java,indent=0] ---- -include::{code-examples}/context/properties/bind/javabean/AppSystemProperties.java[tag=example] +include::{include-springbootfeatures}/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java[tag=*] ---- To specify a session timeout of 30 seconds, `30`, `PT30S` and `30s` are all equivalent. @@ -1708,7 +1453,7 @@ If you prefer to use constructor binding, the same properties can be exposed, as [source,java,indent=0] ---- -include::{code-examples}/context/properties/bind/constructor/AppSystemProperties.java[tag=example] +include::{include-springbootfeatures}/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java[tag=*] ---- @@ -1749,7 +1494,7 @@ Consider the following example: [source,java,indent=0] ---- -include::{code-examples}/context/properties/bind/javabean/AppIoProperties.java[tag=example] +include::{include-springbootfeatures}/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java[tag=*] ---- To specify a buffer size of 10 megabytes, `10` and `10MB` are equivalent. @@ -1770,7 +1515,7 @@ If you prefer to use constructor binding, the same properties can be exposed, as [source,java,indent=0] ---- -include::{code-examples}/context/properties/bind/constructor/AppIoProperties.java[tag=example] +include::{include-springbootfeatures}/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java[tag=*] ---- TIP: If you are upgrading a `Long` property, make sure to define the unit (using `@DataSizeUnit`) if it isn't bytes. @@ -1786,16 +1531,7 @@ To do so, ensure that a compliant JSR-303 implementation is on your classpath an [source,java,indent=0] ---- - @ConfigurationProperties(prefix="acme") - @Validated - public class AcmeProperties { - - @NotNull - private InetAddress remoteAddress; - - // ... getters and setters - - } +include::{include-springbootfeatures}/externalizedconfiguration/validate/AcmeProperties.java[tag=*] ---- TIP: You can also trigger validation by annotating the `@Bean` method that creates the configuration properties with `@Validated`. @@ -1805,28 +1541,7 @@ The following example builds on the preceding `AcmeProperties` example: [source,java,indent=0] ---- - @ConfigurationProperties(prefix="acme") - @Validated - public class AcmeProperties { - - @NotNull - private InetAddress remoteAddress; - - @Valid - private final Security security = new Security(); - - // ... getters and setters - - public static class Security { - - @NotEmpty - public String username; - - // ... getters and setters - - } - - } +include::{include-springbootfeatures}/externalizedconfiguration/validate/nested/AcmeProperties.java[tag=*] ---- You can also add a custom Spring `Validator` by creating a bean definition called `configurationPropertiesValidator`. @@ -1883,13 +1598,7 @@ Any `@Component`, `@Configuration` or `@ConfigurationProperties` can be marked w [source,java,indent=0] ---- - @Configuration(proxyBeanMethods = false) - @Profile("production") - public class ProductionConfiguration { - - // ... - - } +include::{include-springbootfeatures}/profiles/ProductionConfiguration.java[tag=*] ---- NOTE: If `@ConfigurationProperties` beans are registered via `@EnableConfigurationProperties` instead of automatic scanning, the `@Profile` annotation needs to be specified on the `@Configuration` class that has the `@EnableConfigurationProperties` annotation. @@ -2524,26 +2233,7 @@ The following code shows a typical `@RestController` that serves JSON data: [source,java,indent=0] ---- - @RestController - @RequestMapping(value="/users") - public class MyRestController { - - @RequestMapping(value="/{user}", method=RequestMethod.GET) - public User getUser(@PathVariable Long user) { - // ... - } - - @RequestMapping(value="/{user}/customers", method=RequestMethod.GET) - List getUserCustomers(@PathVariable Long user) { - // ... - } - - @RequestMapping(value="/{user}", method=RequestMethod.DELETE) - public User deleteUser(@PathVariable Long user) { - // ... - } - - } +include::{include-springbootfeatures}/webapplications/servlet/MyRestController.java[tag=*] ---- Spring MVC is part of the core Spring Framework, and detailed information is available in the {spring-framework-docs}/web.html#mvc[reference documentation]. @@ -2593,21 +2283,7 @@ If you need to add or customize converters, you can use Spring Boot's `HttpMessa [source,java,indent=0] ---- - import org.springframework.boot.autoconfigure.http.HttpMessageConverters; - import org.springframework.context.annotation.*; - import org.springframework.http.converter.*; - - @Configuration(proxyBeanMethods = false) - public class MyConfiguration { - - @Bean - public HttpMessageConverters customConverters() { - HttpMessageConverter additional = ... - HttpMessageConverter another = ... - return new HttpMessageConverters(additional, another); - } - - } +include::{include-springbootfeatures}/webapplications/HttpMessageConvertersConfiguration.java[tag=*] ---- Any `HttpMessageConverter` bean that is present in the context is added to the list of converters. @@ -2625,23 +2301,7 @@ You can also use it on classes that contain serializers/deserializers as inner c [source,java,indent=0] ---- - import java.io.*; - import com.fasterxml.jackson.core.*; - import com.fasterxml.jackson.databind.*; - import org.springframework.boot.jackson.*; - - @JsonComponent - public class Example { - - public static class Serializer extends JsonSerializer { - // ... - } - - public static class Deserializer extends JsonDeserializer { - // ... - } - - } +include::{include-springbootfeatures}/webapplications/json/MyJsonComponent.java[tag=*] ---- All `@JsonComponent` beans in the `ApplicationContext` are automatically registered with Jackson. @@ -2650,6 +2310,13 @@ Because `@JsonComponent` is meta-annotated with `@Component`, the usual componen Spring Boot also provides {spring-boot-module-code}/jackson/JsonObjectSerializer.java[`JsonObjectSerializer`] and {spring-boot-module-code}/jackson/JsonObjectDeserializer.java[`JsonObjectDeserializer`] base classes that provide useful alternatives to the standard Jackson versions when serializing objects. See {spring-boot-module-api}/jackson/JsonObjectSerializer.html[`JsonObjectSerializer`] and {spring-boot-module-api}/jackson/JsonObjectDeserializer.html[`JsonObjectDeserializer`] in the Javadoc for details. +The example above can be rewritten to use `JsonObjectSerializer`/`JsonObjectDeserializer` as follows: + +[source,java,indent=0] +---- +include::{include-springbootfeatures}/webapplications/json/object/MyJsonComponent.java[tag=*] +---- + [[boot-features-spring-message-codes]] @@ -2890,25 +2557,7 @@ You can also define a class annotated with `@ControllerAdvice` to customize the [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @ControllerAdvice(basePackageClasses = AcmeController.class) - public class AcmeControllerAdvice extends ResponseEntityExceptionHandler { - - @ExceptionHandler(YourException.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - HttpStatus status = getStatus(request); - return new ResponseEntity<>(new CustomErrorType(status.value(), ex.getMessage()), status); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } - - } +include::{include-springbootfeatures}/webapplications/servlet/MyControllerAdvice.java[tag=*] ---- In the preceding example, if `YourException` is thrown by a controller defined in the same package as `AcmeController`, a JSON representation of the `CustomErrorType` POJO is used instead of the `ErrorAttributes` representation. @@ -2955,19 +2604,9 @@ For more complex mappings, you can also add beans that implement the `ErrorViewR [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - public class MyErrorViewResolver implements ErrorViewResolver { - - @Override - public ModelAndView resolveErrorView(HttpServletRequest request, - HttpStatus status, Map model) { - // Use the request or status to optionally return a ModelAndView - return ... - } - - } +include::{include-springbootfeatures}/webapplications/servlet/MyErrorViewResolver.java[tag=*] ---- - You can also use regular Spring MVC features such as {spring-framework-docs}/web.html#mvc-exceptionhandlers[`@ExceptionHandler` methods] and {spring-framework-docs}/web.html#mvc-ann-controller-advice[`@ControllerAdvice`]. The `ErrorController` then picks up any unhandled exceptions. @@ -2980,35 +2619,14 @@ This abstraction works directly with the underlying embedded servlet container a [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public ErrorPageRegistrar errorPageRegistrar(){ - return new MyErrorPageRegistrar(); - } - - // ... - - private static class MyErrorPageRegistrar implements ErrorPageRegistrar { - - @Override - public void registerErrorPages(ErrorPageRegistry registry) { - registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); - } - - } +include::{include-springbootfeatures}/webapplications/servlet/ErrorPageConfiguration.java[tag=*] ---- NOTE: If you register an `ErrorPage` with a path that ends up being handled by a `Filter` (as is common with some non-Spring web frameworks, like Jersey and Wicket), then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, as shown in the following example: [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public FilterRegistrationBean myFilter() { - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(new MyFilter()); - ... - registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class)); - return registration; - } +include::{include-springbootfeatures}/webapplications/servlet/ServletFilterConfiguration.java[tag=*] ---- Note that the default `FilterRegistrationBean` does not include the `ERROR` dispatcher type. @@ -3052,19 +2670,7 @@ Using {spring-framework-docs}/web.html#mvc-cors-controller[controller method COR [source,java,indent=0] ---- - @Configuration(proxyBeanMethods = false) - public class MyConfiguration { - - @Bean - public WebMvcConfigurer corsConfigurer() { - return new WebMvcConfigurer() { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/api/**"); - } - }; - } - } +include::{include-springbootfeatures}/webapplications/servlet/CorsConfiguration.java[tag=*] ---- @@ -3079,59 +2685,19 @@ The annotation-based one is quite close to the Spring MVC model, as shown in the [source,java,indent=0] ---- - @RestController - @RequestMapping("/users") - public class MyRestController { - - @GetMapping("/{user}") - public Mono getUser(@PathVariable Long user) { - // ... - } - - @GetMapping("/{user}/customers") - public Flux getUserCustomers(@PathVariable Long user) { - // ... - } - - @DeleteMapping("/{user}") - public Mono deleteUser(@PathVariable Long user) { - // ... - } - - } +include::{include-springbootfeatures}/webapplications/webflux/MyRestController.java[tag=*] ---- "`WebFlux.fn`", the functional variant, separates the routing configuration from the actual handling of the requests, as shown in the following example: [source,java,indent=0] ---- - @Configuration(proxyBeanMethods = false) - public class RoutingConfiguration { - - @Bean - public RouterFunction monoRouterFunction(UserHandler userHandler) { - return route(GET("/{user}").and(accept(APPLICATION_JSON)), userHandler::getUser) - .andRoute(GET("/{user}/customers").and(accept(APPLICATION_JSON)), userHandler::getUserCustomers) - .andRoute(DELETE("/{user}").and(accept(APPLICATION_JSON)), userHandler::deleteUser); - } - - } - - @Component - public class UserHandler { - - public Mono getUser(ServerRequest request) { - // ... - } - - public Mono getUserCustomers(ServerRequest request) { - // ... - } +include::{include-springbootfeatures}/webapplications/webflux/fn/RoutingConfiguration.java[tag=*] +---- - public Mono deleteUser(ServerRequest request) { - // ... - } - } +[source,java,indent=0] +---- +include::{include-springbootfeatures}/webapplications/webflux/fn/UserHandler.java[tag=*] ---- WebFlux is part of the Spring Framework and detailed information is available in its {spring-framework-docs}/web-reactive.html#webflux-fn[reference documentation]. @@ -3175,19 +2741,7 @@ If you need to add or customize codecs, you can create a custom `CodecCustomizer [source,java,indent=0] ---- - import org.springframework.boot.web.codec.CodecCustomizer; - - @Configuration(proxyBeanMethods = false) - public class MyConfiguration { - - @Bean - public CodecCustomizer myCodecCustomizer() { - return codecConfigurer -> { - // ... - }; - } - - } +include::{include-springbootfeatures}/webapplications/webflux/CodecConfiguration.java[tag=*] ---- You can also leverage <>. @@ -3260,19 +2814,7 @@ Because a `WebExceptionHandler` is quite low-level, Spring Boot also provides a [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - public class CustomErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { - - // Define constructor here - - @Override - protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { - - return RouterFunctions - .route(aPredicate, aHandler) - .andRoute(anotherPredicate, anotherHandler); - } - - } +include::{include-springbootfeatures}/webapplications/webflux/CustomErrorWebExceptionHandler.java[tag=*] ---- For a more complete picture, you can also subclass `DefaultErrorWebExceptionHandler` directly and override specific methods. @@ -3350,7 +2892,7 @@ Jersey has some native Spring support, so we also provide auto-configuration sup To get started with Jersey, include the `spring-boot-starter-jersey` as a dependency and then you need one `@Bean` of type `ResourceConfig` in which you register all the endpoints, as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Component public class JerseyConfig extends ResourceConfig { @@ -3370,7 +2912,7 @@ For more advanced customizations, you can also register an arbitrary number of b All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` and others), as shown in the following example: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- @Component @Path("/hello") @@ -3493,7 +3035,7 @@ If you need to programmatically configure your embedded servlet container, you c `WebServerFactoryCustomizer` provides access to the `ConfigurableServletWebServerFactory`, which includes numerous customization setter methods. The following example shows programmatically setting the port: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; @@ -3515,7 +3057,7 @@ The following example shows how to customize `TomcatServletWebServerFactory` tha [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -include::{code-examples}/context/embedded/TomcatServerCustomizerExample.java[tag=configuration] +include::{include-springbootfeatures}/webapplications/TomcatServerCustomizer.java[tag=*] ---- @@ -3683,7 +3225,7 @@ This is done on purpose since this builder is stateful and you shouldn't create The following code shows a typical example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service public class MyService { @@ -3767,9 +3309,9 @@ Spring Boot provides convenience methods that can be used to override access rul For example, you can customize your security configuration by adding something like: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- -include::{code-examples}/web/security/CustomWebFluxSecurityExample.java[tag=configuration] +include::{include-springbootfeatures}/security/CustomWebFluxSecurityConfiguration.java[tag=*] ---- @@ -3846,7 +3388,7 @@ By default, Spring Security's `OAuth2LoginAuthenticationFilter` only processes U If you want to customize the `redirect-uri` to use a different pattern, you need to provide configuration to process that custom pattern. For example, for servlet applications, you can add your own `SecurityFilterChain` that resembles the following: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -4170,7 +3712,7 @@ For example, the following section in `application.properties` shows how you can === Using JdbcTemplate Spring's `JdbcTemplate` and `NamedParameterJdbcTemplate` classes are auto-configured, and you can `@Autowire` them directly into your own beans, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; @@ -4230,7 +3772,7 @@ By default, all packages below your main configuration class (the one annotated Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered. A typical entity class resembles the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.myapp.domain; @@ -4293,7 +3835,7 @@ If you use auto-configuration, repositories are searched from the package contai The following example shows a typical Spring Data repository interface definition: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.myapp.domain; @@ -4438,7 +3980,7 @@ The fluent API offered by jOOQ is initiated through the `org.jooq.DSLContext` in Spring Boot auto-configures a `DSLContext` as a Spring Bean and connects it to your application `DataSource`. To use the `DSLContext`, you can `@Autowire` it, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class JooqExample implements CommandLineRunner { @@ -4457,7 +3999,7 @@ TIP: The jOOQ manual tends to use a variable named `create` to hold the `DSLCont You can then use the `DSLContext` to construct your queries, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- public List authorsBornAfter1980() { return this.create.selectFrom(AUTHOR) @@ -4512,7 +4054,7 @@ TIP: The "`How-to`" section includes a < cacheManagerCustomizer() { @@ -5609,7 +5151,7 @@ The following example shows a customizer that configures a specific entry expira [source,java,indent=0] ---- -include::{code-examples}/cache/CouchbaseCacheManagerCustomizationExample.java[tag=configuration] +include::{include-springbootfeatures}/nosql/CouchbaseCacheManagerConfiguration.java[tag=*] ---- @@ -5640,7 +5182,7 @@ The following example shows a customizer that configures a specific time to live [source,java,indent=0] ---- -include::{code-examples}/cache/RedisCacheManagerCustomizationExample.java[tag=configuration] +include::{include-springbootfeatures}/nosql/RedisCacheManagerConfiguration.java[tag=*] ---- @@ -5844,7 +5386,7 @@ You can use the configprop:spring.jms.jndi-name[] property if you need to specif ==== Sending a Message Spring's `JmsTemplate` is auto-configured, and you can autowire it directly into your own beans, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; @@ -5885,7 +5427,7 @@ This also includes sending response messages that have been performed on the sam The following component creates a listener endpoint on the `someQueue` destination: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class MyBean { @@ -5904,7 +5446,7 @@ If you need to create more `JmsListenerContainerFactory` instances or if you wan For instance, the following example exposes another factory that uses a specific `MessageConverter`: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration(proxyBeanMethods = false) static class JmsConfiguration { @@ -5924,8 +5466,7 @@ For instance, the following example exposes another factory that uses a specific Then you can use the factory in any `@JmsListener`-annotated method as follows: -[source,java,indent=0] -[subs="verbatim,quotes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes"] ---- @Component public class MyBean { @@ -5989,7 +5530,7 @@ TIP: See https://spring.io/blog/2010/06/14/understanding-amqp-the-protocol-used- ==== Sending a Message Spring's `AmqpTemplate` and `AmqpAdmin` are auto-configured, and you can autowire them directly into your own beans, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.AmqpTemplate; @@ -6045,7 +5586,7 @@ If a `MessageConverter` or a `MessageRecoverer` bean is defined, it is automatic The following sample component creates a listener endpoint on the `someQueue` queue: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class MyBean { @@ -6067,7 +5608,7 @@ Those two beans are exposed by the auto-configuration. For instance, the following configuration class exposes another factory that uses a specific `MessageConverter`: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration(proxyBeanMethods = false) static class RabbitConfiguration { @@ -6087,7 +5628,7 @@ For instance, the following configuration class exposes another factory that use Then you can use the factory in any `@RabbitListener`-annotated method, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] [subs="verbatim,quotes"] ---- @Component @@ -6140,7 +5681,7 @@ See {spring-boot-autoconfigure-module-code}/kafka/KafkaProperties.java[`KafkaPro ==== Sending a Message Spring's `KafkaTemplate` is auto-configured, and you can autowire it directly in your own beans, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class MyBean { @@ -6169,7 +5710,7 @@ If no `KafkaListenerContainerFactory` has been defined, a default one is automat The following component creates a listener endpoint on the `someTopic` topic: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class MyBean { @@ -6208,7 +5749,7 @@ To use the factory bean, wire `StreamsBuilder` into your `@Bean` as shown in the [source,java,indent=0] ---- -include::{code-examples}/kafka/KafkaStreamsBeanExample.java[tag=configuration] +include::{include-springbootfeatures}/messaging/KafkaStreamsConfiguration.java[tag=*] ---- By default, the streams managed by the `StreamBuilder` object it creates are started automatically. @@ -6291,7 +5832,7 @@ There are several ways to do that: * Provide a system property to map embedded broker addresses into configprop:spring.kafka.bootstrap-servers[] in the test class: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- static { System.setProperty(EmbeddedKafkaBroker.BROKER_LIST_PROPERTY, "spring.kafka.bootstrap-servers"); @@ -6300,7 +5841,7 @@ There are several ways to do that: * Configure a property name on the `@EmbeddedKafka` annotation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @EmbeddedKafka(topics = "someTopic", bootstrapServersProperty = "spring.kafka.bootstrap-servers") @@ -6326,7 +5867,7 @@ The auto-configured `RestTemplateBuilder` ensures that sensible `HttpMessageConv The following code shows a typical example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service public class MyService { @@ -6363,7 +5904,7 @@ The following example shows a customizer that configures the use of a proxy for [source,java,indent=0] ---- -include::{code-examples}/web/client/RestTemplateProxyCustomizationExample.java[tag=customizer] +include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizer.java[tag=*] ---- Finally, you can also create your own `RestTemplateBuilder` bean. @@ -6372,7 +5913,7 @@ The following example exposes a `RestTemplateBuilder` with what Spring Boot woul [source,java,indent=0] ---- -include::{code-examples}/web/client/RestTemplateBuilderCustomizationExample.java[tag=customizer] +include::{include-springbootfeatures}/resttemplate/RestTemplateBuilderConfiguration.java[tag=*] ---- The most extreme (and rarely used) option is to create your own `RestTemplateBuilder` bean without using a configurer. @@ -6391,7 +5932,7 @@ Spring Boot is configuring that builder to share HTTP resources, reflect codecs The following code shows a typical example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service public class MyService { @@ -6452,7 +5993,7 @@ Target classes with such annotated methods need to be annotated with the `@Valid For instance, the following service triggers the validation of the first argument, making sure its size is between 8 and 10: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service @Validated @@ -6552,7 +6093,7 @@ For consistency, the `jmsConnectionFactory` bean is also provided by using the b The following example shows how to inject `ConnectionFactory` instances: -[source,java,indent=0,subs="verbatim,quotes,attributes"] +[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] ---- // Inject the primary (XA aware) ConnectionFactory @Autowired @@ -6670,7 +6211,7 @@ If you need to customize the task executor, consider implementing `SchedulerFact Jobs can define setters to inject data map properties. Regular beans can also be injected in a similar manner, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- public class SampleJob extends QuartzJobBean { @@ -6954,7 +6495,7 @@ If you have only Spring WebFlux, we'll detect that and configure a WebFlux-based If both are present, Spring MVC takes precedence. If you want to test a reactive web application in this scenario, you must set the configprop:spring.main.web-application-type[] property: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @SpringBootTest(properties = "spring.main.web-application-type=reactive") class MyWebFluxTests { ... } @@ -6998,7 +6539,7 @@ As we <>. @@ -7046,7 +6587,7 @@ Alternatively, you can configure a {spring-framework-docs}/testing.html#webtestc [source,java,indent=0] ---- -include::{code-examples}/test/web/MockWebTestClientExampleTests.java[tag=test-mock-web-test-client] +include::{include-springbootfeatures}/testing/MockWebTestClientTests.java[tag=*] ---- [TIP] @@ -7071,7 +6612,7 @@ For convenience, tests that need to make REST calls to the started server can ad [source,java,indent=0] ---- -include::{code-examples}/test/web/RandomPortWebTestClientExampleTests.java[tag=test-random-port] +include::{include-springbootfeatures}/testing/RandomPortWebTestClientTests.java[tag=*] ---- This setup requires `spring-webflux` on the classpath. @@ -7079,7 +6620,7 @@ If you can't or won't add webflux, Spring Boot also provides a `TestRestTemplate [source,java,indent=0] ---- -include::{code-examples}/test/web/RandomPortTestRestTemplateExampleTests.java[tag=test-random-port] +include::{include-springbootfeatures}/testing/RandomPortTestRestTemplateTests.java[tag=*] ---- @@ -7098,7 +6639,7 @@ If such test needs access to an `MBeanServer`, consider marking it dirty as well [source,java,indent=0] ---- -include::{test-examples}/jmx/SampleJmxTests.java[tag=test] +include::{include-springbootfeatures}/testing/jmx/SampleJmxTests.java[tag=*] ---- @@ -7128,7 +6669,7 @@ Mock beans are automatically reset after each test method. If your test uses one of Spring Boot's test annotations (such as `@SpringBootTest`), this feature is automatically enabled. To use this feature with a different arrangement, a listener must be explicitly added, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @TestExecutionListeners(MockitoTestExecutionListener.class) ---- @@ -7137,7 +6678,7 @@ To use this feature with a different arrangement, a listener must be explicitly The following example replaces an existing `RemoteService` bean with a mock implementation: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.*; @@ -7228,7 +6769,7 @@ The `JacksonTester`, `GsonTester`, `JsonbTester`, and `BasicJsonTester` classes Any helper fields on the test class can be `@Autowired` when using `@JsonTest`. The following example shows a test class for Jackson: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.*; @@ -7273,11 +6814,11 @@ If you're using Spring Boot's AssertJ-based helpers to assert on a number value Instead, you can use AssertJ's `satisfies` to assert that the value matches the given condition. For instance, the following example asserts that the actual number is a float value close to `0.15` within an offset of `0.01`. -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- -assertThat(json.write(message)) - .extractingJsonPathNumberValue("@.test.numberValue") - .satisfies((number) -> assertThat(number.floatValue()).isCloseTo(0.15f, within(0.01f))); + assertThat(json.write(message)) + .extractingJsonPathNumberValue("@.test.numberValue") + .satisfies((number) -> assertThat(number.floatValue()).isCloseTo(0.15f, within(0.01f))); ---- @@ -7301,7 +6842,7 @@ Mock MVC offers a powerful way to quickly test MVC controllers without needing t TIP: You can also auto-configure `MockMvc` in a non-`@WebMvcTest` (such as `@SpringBootTest`) by annotating it with `@AutoConfigureMockMvc`. The following example uses `MockMvc`: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.*; @@ -7338,7 +6879,7 @@ TIP: If you need to configure elements of the auto-configuration (for example, w If you use HtmlUnit or Selenium, auto-configuration also provides an HtmlUnit `WebClient` bean and/or a Selenium `WebDriver` bean. The following example uses HtmlUnit: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import com.gargoylesoftware.htmlunit.*; import org.junit.jupiter.api.*; @@ -7401,7 +6942,7 @@ Often, `@WebFluxTest` is limited to a single controller and used in combination TIP: You can also auto-configure `WebTestClient` in a non-`@WebFluxTest` (such as `@SpringBootTest`) by annotating it with `@AutoConfigureWebTestClient`. The following example shows a class that uses both `@WebFluxTest` and a `WebTestClient`: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; @@ -7456,7 +6997,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataCassand The following example shows a typical setup for using Cassandra tests in Spring Boot: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest; @@ -7487,7 +7028,7 @@ By default, data JPA tests are transactional and roll back at the end of each te See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details. If that is not what you want, you can disable transaction management for a test or for the whole class as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -7506,7 +7047,7 @@ If you want to use `TestEntityManager` outside of `@DataJpaTest` instances, you A `JdbcTemplate` is also available if you need that. The following example shows the `@DataJpaTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.orm.jpa.*; @@ -7536,7 +7077,7 @@ The following example shows the `@DataJpaTest` annotation in use: In-memory embedded databases generally work well for tests, since they are fast and do not require any installation. If, however, you prefer to run tests against a real database you can use the `@AutoConfigureTestDatabase` annotation, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @DataJpaTest @AutoConfigureTestDatabase(replace=Replace.NONE) @@ -7562,7 +7103,7 @@ By default, JDBC tests are transactional and roll back at the end of each test. See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details. If that is not what you want, you can disable transaction management for a test or for the whole class, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; @@ -7613,7 +7154,7 @@ TIP: A list of the auto-configurations that are enabled by `@JooqTest` can be << `@JooqTest` configures a `DSLContext`. The following example shows the `@JooqTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.jooq.DSLContext; import org.junit.jupiter.api.Test; @@ -7644,7 +7185,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataMongoTe The following class shows the `@DataMongoTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; @@ -7663,7 +7204,7 @@ The following class shows the `@DataMongoTest` annotation in use: In-memory embedded MongoDB generally works well for tests, since it is fast and does not require any developer installation. If, however, you prefer to run tests against a real MongoDB server, you should exclude the embedded MongoDB auto-configuration, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; @@ -7688,7 +7229,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataNeo4jTe The following example shows a typical setup for using Neo4J tests in Spring Boot: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest; @@ -7707,7 +7248,7 @@ By default, Data Neo4j tests are transactional and roll back at the end of each See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details. If that is not what you want, you can disable transaction management for a test or for the whole class, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest; import org.springframework.transaction.annotation.Propagation; @@ -7737,7 +7278,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataRedisTe The following example shows the `@DataRedisTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest; @@ -7766,7 +7307,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataLdapTes The following example shows the `@DataLdapTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest; @@ -7785,7 +7326,7 @@ The following example shows the `@DataLdapTest` annotation in use: In-memory embedded LDAP generally works well for tests, since it is fast and does not require any developer installation. If, however, you prefer to run tests against a real LDAP server, you should exclude the embedded LDAP auto-configuration, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration; import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest; @@ -7809,7 +7350,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@RestClientT The specific beans that you want to test should be specified by using the `value` or `components` attribute of `@RestClientTest`, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @RestClientTest(RemoteVehicleDetailsService.class) class ExampleRestClientTest { @@ -7849,7 +7390,7 @@ It can also be used to configure the host, scheme, and port that appears in any `@AutoConfigureRestDocs` customizes the `MockMvc` bean to use Spring REST Docs when testing Servlet-based web applications. You can inject it by using `@Autowired` and use it in your tests as you normally would when using Mock MVC and Spring REST Docs, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.junit.jupiter.api.Test; @@ -7881,7 +7422,7 @@ You can inject it by using `@Autowired` and use it in your tests as you normally If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, you can use a `RestDocsMockMvcConfigurationCustomizer` bean, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @TestConfiguration static class CustomizationConfiguration @@ -7899,7 +7440,7 @@ If you want to make use of Spring REST Docs support for a parameterized output d The auto-configuration calls `alwaysDo` with this result handler, thereby causing each `MockMvc` call to automatically generate the default snippets. The following example shows a `RestDocumentationResultHandler` being defined: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @TestConfiguration(proxyBeanMethods = false) static class ResultHandlerConfiguration { @@ -7921,14 +7462,14 @@ You can inject it by using `@Autowired` and use it in your tests as you normally [source,java,indent=0] ---- -include::{code-examples}/test/autoconfigure/restdocs/webclient/UsersDocumentationTests.java[tag=source] +include::{include-springbootfeatures}/testing/restdocs/webclient/UsersDocumentationTests.java[tag=*] ---- If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, you can use a `RestDocsWebTestClientConfigurationCustomizer` bean, as shown in the following example: [source,java,indent=0] ---- -include::{code-examples}/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java[tag=configuration] +include::{include-springbootfeatures}/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java[tag=*] ---- @@ -7940,14 +7481,14 @@ You can inject it by using `@Autowired` and use it in your tests as you normally [source,java,indent=0] ---- -include::{code-examples}/test/autoconfigure/restdocs/restassured/UserDocumentationTests.java[tag=source] +include::{include-springbootfeatures}/testing/restdocs/restassured/UserDocumentationTests.java[tag=*] ---- If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, a `RestDocsRestAssuredConfigurationCustomizer` bean can be used, as shown in the following example: [source,java,indent=0] ---- -include::{code-examples}/test/autoconfigure/restdocs/restassured/AdvancedConfigurationExample.java[tag=configuration] +include::{include-springbootfeatures}/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java[tag=*] ---- @@ -7963,7 +7504,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@WebServiceC The following example shows the `@WebServiceClientTest` annotation in use: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @WebServiceClientTest(ExampleWebServiceClient.class) class WebServiceClientIntegrationTests { @@ -7991,7 +7532,7 @@ The following example shows the `@WebServiceClientTest` annotation in use: Each slice provides one or more `@AutoConfigure...` annotations that namely defines the auto-configurations that should be included as part of a slice. Additional auto-configurations can be added on a test-by-test basis by creating a custom `@AutoConfigure...` annotation or by adding `@ImportAutoConfiguration` to the test as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @JdbcTest @ImportAutoConfiguration(IntegrationAutoConfiguration.class) @@ -8022,7 +7563,7 @@ It then becomes important not to litter the application's main class with config Assume that you are using Spring Batch and you rely on the auto-configuration for it. You could define your `@SpringBootApplication` as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @SpringBootApplication @EnableBatchProcessing @@ -8032,7 +7573,7 @@ You could define your `@SpringBootApplication` as follows: Because this class is the source configuration for the test, any slice test actually tries to start Spring Batch, which is definitely not what you want to do. A recommended approach is to move that area-specific configuration to a separate `@Configuration` class at the same level as your application, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration(proxyBeanMethods = false) @EnableBatchProcessing @@ -8045,7 +7586,7 @@ The latter approach lets you enable it in one of your tests, if necessary, with Test slices exclude `@Configuration` classes from scanning. For example, for a `@WebMvcTest`, the following configuration will not include the given `WebMvcConfigurer` bean in the application context loaded by the test slice: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration public class WebConfiguration { @@ -8060,7 +7601,7 @@ For example, for a `@WebMvcTest`, the following configuration will not include t The configuration below will, however, cause the custom `WebMvcConfigurer` to be loaded by the test slice. -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Component public class TestWebMvcConfigurer implements WebMvcConfigurer { @@ -8072,7 +7613,7 @@ Another source of confusion is classpath scanning. Assume that, while you structured your code in a sensible way, you need to scan an additional package. Your application may resemble the following code: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @SpringBootApplication @ComponentScan({ "com.example.app", "org.acme.another" }) @@ -8110,7 +7651,7 @@ A few test utility classes that are generally useful when testing your applicati `ConfigFileApplicationContextInitializer` is an `ApplicationContextInitializer` that you can apply to your tests to load Spring Boot `application.properties` files. You can use it when you do not need the full set of features provided by `@SpringBootTest`, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @ContextConfiguration(classes = Config.class, initializers = ConfigFileApplicationContextInitializer.class) @@ -8127,7 +7668,7 @@ For `@Value` support, you need to either additionally configure a `PropertySourc `TestPropertyValues` lets you quickly add properties to a `ConfigurableEnvironment` or `ConfigurableApplicationContext`. You can call it with `key=value` strings, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- TestPropertyValues.of("org=Spring", "name=Boot").applyTo(env); ---- @@ -8141,7 +7682,7 @@ To use add `@ExtendWith(OutputCaptureExtension.class)` and inject `CapturedOutpu [source,java,indent=0] ---- -include::{test-examples}/test/system/OutputCaptureTests.java[tag=test] +include::{include-springbootfeatures}/testing/OutputCaptureTests.java[tag=*] ---- @@ -8164,7 +7705,7 @@ If you do use Apache's HTTP client, some additional test-friendly features are e `TestRestTemplate` can be instantiated directly in your integration tests, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- public class MyTest { @@ -8186,7 +7727,7 @@ Any URLs that do not specify a host and port automatically connect to the embedd [source,java,indent=0] ---- -include::{test-examples}/web/client/SampleWebClientTests.java[tag=test] +include::{include-springbootfeatures}/testing/webclient/SampleWebClientTests.java[tag=*] ---- @@ -8237,7 +7778,7 @@ It does, however, auto-configure a `WebServiceTemplateBuilder`, which can be use The following code shows a typical example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service public class MyService { @@ -8258,7 +7799,7 @@ The following code shows a typical example: By default, `WebServiceTemplateBuilder` detects a suitable HTTP-based `WebServiceMessageSender` using the available HTTP client libraries on the classpath. You can also customize read and connection timeouts as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Bean public WebServiceTemplate webServiceTemplate(WebServiceTemplateBuilder builder) { @@ -8347,7 +7888,7 @@ This mechanism does not apply the same way to `@Bean` methods where typically th To handle this scenario, a separate `@Configuration` class can be used to isolate the condition, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration(proxyBeanMethods = false) // Some conditions @@ -8380,7 +7921,7 @@ The `search` attribute lets you limit the `ApplicationContext` hierarchy that sh When placed on a `@Bean` method, the target type defaults to the return type of the method, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Configuration(proxyBeanMethods = false) public class MyAutoConfiguration { @@ -8450,7 +7991,7 @@ The following example makes sure that `UserServiceAutoConfiguration` is always i [source,java,indent=0] ---- -include::{test-examples}/autoconfigure/UserServiceAutoConfigurationTests.java[tag=runner] +include::{include-springbootfeatures}/testing/UserServiceAutoConfigurationTests.java[tag=runner] ---- TIP: If multiple auto-configurations have to be defined, there is no need to order their declarations as they are invoked in the exact same order as when running the application. @@ -8461,21 +8002,21 @@ Invoking `run` provides a callback context that can be used with `AssertJ`. [source,java,indent=0] ---- -include::{test-examples}/autoconfigure/UserServiceAutoConfigurationTests.java[tag=test-user-config] +include::{include-springbootfeatures}/testing/UserServiceAutoConfigurationTests.java[tag=test-user-config] ---- It is also possible to easily customize the `Environment`, as shown in the following example: [source,java,indent=0] ---- -include::{test-examples}/autoconfigure/UserServiceAutoConfigurationTests.java[tag=test-env] +include::{include-springbootfeatures}/testing/UserServiceAutoConfigurationTests.java[tag=test-env] ---- The runner can also be used to display the `ConditionEvaluationReport`. The report can be printed at `INFO` or `DEBUG` level. The following example shows how to use the `ConditionEvaluationReportLoggingListener` to print the report in auto-configuration tests. -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Test void autoConfigTest() { @@ -8502,7 +8043,7 @@ In the following example, we assert that if `UserService` is not present, the au [source,java,indent=0] ---- -include::{test-examples}/autoconfigure/UserServiceAutoConfigurationTests.java[tag=test-classloader] +include::{include-springbootfeatures}/testing/UserServiceAutoConfigurationTests.java[tag=test-classloader] ---- @@ -8549,7 +8090,7 @@ As a rule of thumb, prefix all your keys with a namespace that you own (e.g. `ac Make sure that configuration keys are documented by adding field javadoc for each property, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @ConfigurationProperties("acme") public class AcmeProperties { @@ -8902,14 +8443,12 @@ Disable launch script configuration when building a jar file that is intended to Here’s how you can launch your jar with a `layertools` jar mode: -[source] ---- $ java -Djarmode=layertools -jar my-app.jar ---- This will provide the following output: -[source] ---- Usage: java -Djarmode=layertools -jar my-app.jar @@ -8923,7 +8462,6 @@ Available commands: The `extract` command can be used to easily split the application into layers to be added to the dockerfile. Here's an example of a Dockerfile using `jarmode`. -[source] ---- FROM adoptopenjdk:11-jre-hotspot as builder WORKDIR application diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using-spring-boot.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using-spring-boot.adoc index e66c218ae499..3e0d42f654bf 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using-spring-boot.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using-spring-boot.adoc @@ -209,7 +209,7 @@ The following listing shows a typical layout: The `Application.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.myapplication; @@ -282,7 +282,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition === Disabling Specific Auto-configuration Classes If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of `@SpringBootApplication` to disable them, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.jdbc.*; @@ -313,7 +313,7 @@ All of your application components (`@Component`, `@Service`, `@Repository`, `@C The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.service; @@ -337,7 +337,7 @@ The following example shows a `@Service` Bean that uses constructor injection to If a bean has one constructor, you can omit the `@Autowired`, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- @Service public class DatabaseAccountService implements AccountService { @@ -366,7 +366,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f * `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <>) * `@Configuration`: allow to register extra beans in the context or import additional configuration classes -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.myapplication; @@ -390,7 +390,7 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables. For instance, you may not want to use component scan or configuration properties scan in your application: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- package com.example.myapplication; @@ -593,7 +593,7 @@ The way in which you cause the classpath to be updated depends on the IDE that y * In Eclipse, saving a modified file causes the classpath to be updated and triggers a restart. * In IntelliJ IDEA, building the project (`Build +->+ Build Project`) has the same effect. -* If using a build plugin, running `mvn compile` for Maven or `gradle build` for Gradle will trigger a restart. +* If using a build plugin, running `mvn compile` for Maven or `gradle build` for Gradle will trigger a restart. **** NOTE: If you are restarting with Maven or Gradle using the build plugin you must leave the `forking` set to `enabled`. @@ -677,7 +677,7 @@ In most cases, you can set this property in your `application.properties` (doing If you need to _completely_ disable restart support (for example, because it does not work with a specific library), you need to set the configprop:spring.devtools.restart.enabled[] `System` property to `false` before calling `SpringApplication.run(...)`, as shown in the following example: -[source,java,indent=0] +[source,java,pending-extract=true,indent=0] ---- public static void main(String[] args) { System.setProperty("spring.devtools.restart.enabled", "false"); diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java deleted file mode 100644 index 7cc9cd287a77..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.elasticsearch; - -import javax.persistence.EntityManagerFactory; - -import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor; -import org.springframework.stereotype.Component; - -/** - * Example configuration for configuring Hibernate to depend on Elasticsearch so that - * Hibernate Search can use Elasticsearch as its index manager. - * - * @author Andy Wilkinson - */ -public class HibernateSearchElasticsearchExample { - - // tag::configuration[] - /** - * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that - * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean. - */ - @Component - static class ElasticsearchEntityManagerFactoryDependsOnPostProcessor - extends EntityManagerFactoryDependsOnPostProcessor { - - ElasticsearchEntityManagerFactoryDependsOnPostProcessor() { - super("elasticsearchClient"); - } - - } - // end::configuration[] - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java index 531de976adb5..2813360f4766 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,18 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.metrics; +package org.springframework.boot.docs.howto.actuator; +// tag::code[] import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.boot.actuate.health.HealthEndpoint; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.Status; import org.springframework.context.annotation.Configuration; -/** - * Example to show how to export {@link HealthIndicator} beans to a {@link MeterRegistry}. - * - * @author Phillip Webb - */ -public class MetricsHealthMicrometerExportExample { +public class MetricsHealthMicrometerExport { - // tag::configuration[] @Configuration public class HealthMetricsConfiguration { @@ -55,6 +49,6 @@ private int getStatusCode(HealthEndpoint health) { } } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/package-info.java new file mode 100644 index 000000000000..b48bb91aef86 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Actuator" section. + */ +package org.springframework.boot.docs.howto.actuator; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/batchapplications/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/batchapplications/package-info.java new file mode 100644 index 000000000000..ea999e25c1d3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/batchapplications/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Batch Applications" section. + */ +package org.springframework.boot.docs.howto.batchapplications; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/build/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/build/package-info.java new file mode 100644 index 000000000000..d32b64581747 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/build/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Build" section. + */ +package org.springframework.boot.docs.howto.build; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/BasicDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java similarity index 58% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/BasicDataSourceExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java index 674c361e64a5..fd3ca2c6d846 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/BasicDataSourceExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import javax.sql.DataSource; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -23,27 +24,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring a very basic custom {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class BasicDataSourceExample { - - /** - * A configuration that exposes an empty {@link DataSource}. - */ - @Configuration(proxyBeanMethods = false) - public static class BasicDataSourceConfiguration { - - // tag::configuration[] - @Bean - @ConfigurationProperties("app.datasource") - public DataSource dataSource() { - return DataSourceBuilder.create().build(); - } - // end::configuration[] +@Configuration(proxyBeanMethods = false) +public class BasicDataSourceConfiguration { + @Bean + @ConfigurationProperties("app.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/CaseSensitiveSpringPhysicalNamingStrategyExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java similarity index 73% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/CaseSensitiveSpringPhysicalNamingStrategyExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java index d8c34d71fd7b..52f00426e391 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/CaseSensitiveSpringPhysicalNamingStrategyExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,18 @@ * limitations under the License. */ -package org.springframework.boot.docs.jpa; +package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; -/** - * Example configuration for defining a custom {@link SpringPhysicalNamingStrategy} that - * is case sensitive. - * - * @author Andy Wilkinson - */ -class CaseSensitiveSpringPhysicalNamingStrategyExample { +@Configuration +class CaseSensitiveSpringPhysicalNamingStrategyConfiguration { - // tag::naming-strategy[] @Bean SpringPhysicalNamingStrategy caseSensitivePhysicalNamingStrategy() { return new SpringPhysicalNamingStrategy() { @@ -41,6 +37,6 @@ protected boolean isCaseInsensitive(JdbcEnvironment jdbcEnvironment) { }; } - // end::naming-strategy[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java new file mode 100644 index 000000000000..e651b6d2a053 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.dataaccess; + +// tag::code[] +import com.zaxxer.hikari.HikariDataSource; +import org.apache.commons.dbcp2.BasicDataSource; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class CompleteDataSourcesConfiguration { + + @Bean + @Primary + @ConfigurationProperties("app.datasource.first") + public DataSourceProperties firstDataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + @Primary + @ConfigurationProperties("app.datasource.first.configuration") + public HikariDataSource firstDataSource() { + return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } + + @Bean + @ConfigurationProperties("app.datasource.second") + public DataSourceProperties secondDataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + @ConfigurationProperties("app.datasource.second.configuration") + public BasicDataSource secondDataSource() { + return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java new file mode 100644 index 000000000000..4f0af432f5e6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.dataaccess; + +// tag::code[] +import com.zaxxer.hikari.HikariDataSource; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration(proxyBeanMethods = false) +public class ConfigurableDataSourceConfiguration { + + @Bean + @Primary + @ConfigurationProperties("app.datasource") + public DataSourceProperties dataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + @ConfigurationProperties("app.datasource.configuration") + public HikariDataSource dataSource(DataSourceProperties properties) { + return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java new file mode 100644 index 000000000000..737ac85e316c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.dataaccess; + +// tag::code[] +import javax.persistence.EntityManagerFactory; + +import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor; +import org.springframework.stereotype.Component; + +/** + * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that + * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean. + */ +@Component +public class ElasticsearchEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { + + ElasticsearchEntityManagerFactoryDependsOnPostProcessor() { + super("elasticsearchClient"); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/HibernateSecondLevelCacheExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/HibernateSecondLevelCacheExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java index 75c9bce2027f..e6fffd5302dd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/HibernateSecondLevelCacheExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.jpa; +package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import org.hibernate.cache.jcache.ConfigSettings; import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer; @@ -23,14 +24,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration of using JCache and Hibernate to enable second level caching. - * - * @author Stephane Nicoll - */ -// tag::configuration[] @Configuration(proxyBeanMethods = false) -public class HibernateSecondLevelCacheExample { +public class HibernateSecondLevelCacheConfiguration { @Bean public HibernatePropertiesCustomizer hibernateSecondLevelCacheCustomizer(JCacheCacheManager cacheManager) { @@ -38,4 +33,4 @@ public HibernatePropertiesCustomizer hibernateSecondLevelCacheCustomizer(JCacheC } } -// end::configuration[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/r2dbc/R2dbcDatabaseInitializationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java similarity index 55% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/r2dbc/R2dbcDatabaseInitializationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java index e5236b2b916a..01625798d3e3 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/r2dbc/R2dbcDatabaseInitializationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.r2dbc; +package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import io.r2dbc.spi.ConnectionFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,26 +26,16 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator; -/** - * Example configuration for initializing a database using R2DBC. - * - * @author Stephane Nicoll - */ -public class R2dbcDatabaseInitializationExample { - - // tag::configuration[] - @Configuration(proxyBeanMethods = false) - static class DatabaseInitializationConfiguration { - - @Autowired - void initializeDatabase(ConnectionFactory connectionFactory) { - ResourceLoader resourceLoader = new DefaultResourceLoader(); - Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:schema.sql"), - resourceLoader.getResource("classpath:data.sql") }; - new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); - } +@Configuration(proxyBeanMethods = false) +public class R2dbcDatabaseInitializationConfiguration { + @Autowired + void initializeDatabase(ConnectionFactory connectionFactory) { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:schema.sql"), + resourceLoader.getResource("classpath:data.sql") }; + new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java similarity index 56% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java index 7dec69c4b2f5..88df89cf2589 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; - -import javax.sql.DataSource; +package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import com.zaxxer.hikari.HikariDataSource; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -25,27 +24,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring a simple {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class SimpleDataSourceExample { - - /** - * A simple configuration that exposes dedicated settings. - */ - @Configuration(proxyBeanMethods = false) - public static class SimpleDataSourceConfiguration { - - // tag::configuration[] - @Bean - @ConfigurationProperties("app.datasource") - public HikariDataSource dataSource() { - return DataSourceBuilder.create().type(HikariDataSource.class).build(); - } - // end::configuration[] +@Configuration(proxyBeanMethods = false) +public class SimpleDataSourceConfiguration { + @Bean + @ConfigurationProperties("app.datasource") + public HikariDataSource dataSource() { + return DataSourceBuilder.create().type(HikariDataSource.class).build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java new file mode 100644 index 000000000000..434e97a290dc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.dataaccess; + +// tag::code[] +import com.zaxxer.hikari.HikariDataSource; +import org.apache.commons.dbcp2.BasicDataSource; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class SimpleDataSourcesConfiguration { + + @Bean + @Primary + @ConfigurationProperties("app.datasource.first") + public DataSourceProperties firstDataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + @Primary + @ConfigurationProperties("app.datasource.first.configuration") + public HikariDataSource firstDataSource() { + return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } + + @Bean + @ConfigurationProperties("app.datasource.second") + public BasicDataSource secondDataSource() { + return DataSourceBuilder.create().type(BasicDataSource.class).build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/package-info.java new file mode 100644 index 000000000000..10e523a65964 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Data Access" section. + */ +package org.springframework.boot.docs.howto.dataaccess; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/databaseinitialization/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/databaseinitialization/package-info.java new file mode 100644 index 000000000000..612af6947711 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/databaseinitialization/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Database Initialization" section. + */ +package org.springframework.boot.docs.howto.databaseinitialization; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java similarity index 53% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java index f2bb5d298aa6..4ccb9f6daefc 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.howto.embeddedwebservers; +// tag::code[] import org.apache.tomcat.util.http.LegacyCookieProcessor; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -23,27 +24,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring Tomcat with to use {@link LegacyCookieProcessor}. - * - * @author Andy Wilkinson - */ -public class TomcatLegacyCookieProcessorExample { - - /** - * Configuration class that declares the required {@link WebServerFactoryCustomizer}. - */ - @Configuration(proxyBeanMethods = false) - public static class LegacyCookieProcessorConfiguration { - - // tag::customizer[] - @Bean - public WebServerFactoryCustomizer cookieProcessorCustomizer() { - return (factory) -> factory - .addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor())); - } - // end::customizer[] +@Configuration(proxyBeanMethods = false) +public class LegacyCookieProcessorConfiguration { + @Bean + public WebServerFactoryCustomizer cookieProcessorCustomizer() { + return (factory) -> factory + .addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor())); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatMultipleConnectorsExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatMultipleConnectorsExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java index b584448ed5ec..62569aeb198b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatMultipleConnectorsExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.howto.embeddedwebservers; +// tag::code[] import java.io.IOException; import java.net.URL; @@ -28,15 +29,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.ResourceUtils; -/** - * Example configuration for configuring Tomcat with an additional {@link Connector}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class TomcatMultipleConnectorsExample { +public class TomcatMultipleConnectorsConfiguration { - // tag::configuration[] @Bean public WebServerFactoryCustomizer sslConnectorCustomizer() { return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createSslConnector()); @@ -63,6 +58,6 @@ private Connector createSslConnector() { throw new IllegalStateException("Fail to create ssl connector", ex); } } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/UndertowMultipleListenersExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java similarity index 65% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/UndertowMultipleListenersExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java index bad053f8a9f5..bed31b8b10ce 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/UndertowMultipleListenersExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java @@ -14,38 +14,27 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.howto.embeddedwebservers; import io.undertow.Undertow.Builder; -import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer; +//tag::code[] import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring Undertow with an additional listener. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class UndertowMultipleListenersExample { +public class UndertowMultipleListenersConfiguration { - // tag::configuration[] @Bean public WebServerFactoryCustomizer undertowListenerCustomizer() { - return (factory) -> { - factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { - - @Override - public void customize(Builder builder) { - builder.addHttpListener(8080, "0.0.0.0"); - } + return (factory) -> factory.addBuilderCustomizers(this::addHttpListener); + } - }); - }; + private Builder addHttpListener(Builder builder) { + return builder.addHttpListener(8080, "0.0.0.0"); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/package-info.java new file mode 100644 index 000000000000..39d341eda5ff --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Embedded Web Servers" section. + */ +package org.springframework.boot.docs.howto.embeddedwebservers; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/hotswapping/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/hotswapping/package-info.java new file mode 100644 index 000000000000..e2a273bf01c9 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/hotswapping/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Hot Swapping" section. + */ +package org.springframework.boot.docs.howto.hotswapping; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/reactive/function/client/ReactorNettyClientCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java similarity index 77% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/reactive/function/client/ReactorNettyClientCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java index ff2e7f9541fe..d476add98580 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/reactive/function/client/ReactorNettyClientCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.reactive.function.client; +package org.springframework.boot.docs.howto.httpclients; +// tag::code[] import io.netty.channel.ChannelOption; import io.netty.handler.timeout.ReadTimeoutHandler; import reactor.netty.http.client.HttpClient; @@ -25,17 +26,10 @@ import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.client.reactive.ReactorResourceFactory; -import org.springframework.web.reactive.function.client.WebClient; -/** - * Example configuration for customizing the Reactor Netty-based {@link WebClient}. - * - * @author Andy Wilkinson - */ @Configuration(proxyBeanMethods = false) -public class ReactorNettyClientCustomizationExample { +public class CustomizeReactorNettyClientConfiguration { - // tag::custom-http-connector[] @Bean ClientHttpConnector clientHttpConnector(ReactorResourceFactory resourceFactory) { HttpClient httpClient = HttpClient.create(resourceFactory.getConnectionProvider()) @@ -43,6 +37,6 @@ ClientHttpConnector clientHttpConnector(ReactorResourceFactory resourceFactory) .doOnConnected((connection) -> connection.addHandlerLast(new ReadTimeoutHandler(60))); return new ReactorClientHttpConnector(httpClient); } - // end::custom-http-connector[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/package-info.java new file mode 100644 index 000000000000..d27b0e13109b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - HTTP Clients" section. + */ +package org.springframework.boot.docs.howto.httpclients; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java new file mode 100644 index 000000000000..52a5be8ab525 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.jersey; + +// tag::code[] +import java.util.Collections; + +import org.glassfish.jersey.server.ResourceConfig; + +import org.springframework.stereotype.Component; + +@Component +public class JerseySetStatusOverSendErrorConfig extends ResourceConfig { + + public JerseySetStatusOverSendErrorConfig() { + register(Endpoint.class); + setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); + } + +} +// end::code[] + +class Endpoint { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/package-info.java new file mode 100644 index 000000000000..ef3a388de67a --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Jersey" section. + */ +package org.springframework.boot.docs.howto.jersey; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/logging/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/logging/package-info.java new file mode 100644 index 000000000000..2fe9a206ea83 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/logging/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Logging" section. + */ +package org.springframework.boot.docs.howto.logging; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/package-info.java new file mode 100644 index 000000000000..5dea09cf3e1c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Messaging" section. + */ +package org.springframework.boot.docs.howto.messaging; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/package-info.java new file mode 100644 index 000000000000..dcfd0d12b2de --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Properties and Configuration" section. + */ +package org.springframework.boot.docs.howto.propertiesandconfiguration; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/package-info.java new file mode 100644 index 000000000000..bd36bd612dd2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Security" section. + */ +package org.springframework.boot.docs.howto.security; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessor.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessor.java index 2bfef078e9e8..fc0e6b7066e0 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.context; +package org.springframework.boot.docs.howto.springbootapplication; +// tag::code[] import java.io.IOException; import org.springframework.boot.SpringApplication; @@ -25,14 +26,9 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.util.Assert; -/** - * An {@link EnvironmentPostProcessor} example that loads a YAML file. - * - * @author Stephane Nicoll - */ -// tag::example[] -public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor { +public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor { private final YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); @@ -44,9 +40,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp } private PropertySource loadYaml(Resource path) { - if (!path.exists()) { - throw new IllegalArgumentException("Resource " + path + " does not exist"); - } + Assert.isTrue(path.exists(), () -> "Resource " + path + " does not exist"); try { return this.loader.load("custom-resource", path).get(0); } @@ -56,4 +50,4 @@ private PropertySource loadYaml(Resource path) { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/package-info.java new file mode 100644 index 000000000000..7312f7df3a58 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Spring Boot Application" section. + */ +package org.springframework.boot.docs.howto.springbootapplication; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/package-info.java new file mode 100644 index 000000000000..3473857d6609 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Spring MVC" section. + */ +package org.springframework.boot.docs.howto.springmvc; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/package-info.java new file mode 100644 index 000000000000..6f0a7114c6da --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Testing with Spring Security" section. + */ +package org.springframework.boot.docs.howto.testingwithspringsecurity; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/package-info.java new file mode 100644 index 000000000000..45cf58f6dc62 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "How-to - Traditional Deployment" section. + */ +package org.springframework.boot.docs.howto.traditionaldeployment; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExample.java deleted file mode 100644 index 7526b6331de5..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExample.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.jdbc; - -import com.zaxxer.hikari.HikariDataSource; -import org.apache.commons.dbcp2.BasicDataSource; - -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * Example configuration for configuring two data sources with what Spring Boot does in - * auto-configuration. - * - * @author Stephane Nicoll - */ -public class CompleteTwoDataSourcesExample { - - /** - * A complete configuration that exposes two data sources. - */ - @Configuration - public static class CompleteDataSourcesConfiguration { - - // tag::configuration[] - @Bean - @Primary - @ConfigurationProperties("app.datasource.first") - public DataSourceProperties firstDataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @Primary - @ConfigurationProperties("app.datasource.first.configuration") - public HikariDataSource firstDataSource() { - return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - - @Bean - @ConfigurationProperties("app.datasource.second") - public DataSourceProperties secondDataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @ConfigurationProperties("app.datasource.second.configuration") - public BasicDataSource secondDataSource() { - return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build(); - } - // end::configuration[] - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExample.java deleted file mode 100644 index e9517f752f71..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExample.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.jdbc; - -import javax.sql.DataSource; - -import com.zaxxer.hikari.HikariDataSource; - -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * Example configuration for configuring a configurable custom {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class ConfigurableDataSourceExample { - - /** - * A configuration that defines dedicated settings and reuses - * {@link DataSourceProperties}. - */ - @Configuration(proxyBeanMethods = false) - public static class ConfigurableDataSourceConfiguration { - - // tag::configuration[] - @Bean - @Primary - @ConfigurationProperties("app.datasource") - public DataSourceProperties dataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @ConfigurationProperties("app.datasource.configuration") - public HikariDataSource dataSource(DataSourceProperties properties) { - return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - // end::configuration[] - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExample.java deleted file mode 100644 index 568d465da0c6..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExample.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.jdbc; - -import javax.sql.DataSource; - -import com.zaxxer.hikari.HikariDataSource; -import org.apache.commons.dbcp2.BasicDataSource; - -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * Example configuration for configuring a configurable secondary {@link DataSource} while - * keeping the auto-configuration defaults for the primary one. - * - * @author Stephane Nicoll - */ -public class SimpleTwoDataSourcesExample { - - /** - * A simple configuration that exposes two data sources. - */ - @Configuration - public static class SimpleDataSourcesConfiguration { - - // tag::configuration[] - @Bean - @Primary - @ConfigurationProperties("app.datasource.first") - public DataSourceProperties firstDataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @Primary - @ConfigurationProperties("app.datasource.first.configuration") - public HikariDataSource firstDataSource() { - return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - - @Bean - @ConfigurationProperties("app.datasource.second") - public BasicDataSource secondDataSource() { - return DataSourceBuilder.create().type(BasicDataSource.class).build(); - } - // end::configuration[] - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jersey/JerseySetStatusOverSendErrorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jersey/JerseySetStatusOverSendErrorExample.java deleted file mode 100644 index 0874f9f0e7ca..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jersey/JerseySetStatusOverSendErrorExample.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.jersey; - -import java.util.Collections; - -import javax.servlet.http.HttpServletResponse; - -import org.glassfish.jersey.server.ResourceConfig; - -import org.springframework.stereotype.Component; - -/** - * Example configuration for a Jersey {@link ResourceConfig} configured to use - * {@link HttpServletResponse#setStatus(int)} rather than - * {@link HttpServletResponse#sendError(int)}. - * - * @author Andy Wilkinson - */ -public class JerseySetStatusOverSendErrorExample { - - // tag::resource-config[] - @Component - public class JerseyConfig extends ResourceConfig { - - public JerseyConfig() { - register(Endpoint.class); - setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); - } - - } - // end::resource-config[] - - static class Endpoint { - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/auditing/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/auditing/package-info.java new file mode 100644 index 000000000000..66e57e05fa4a --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/auditing/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Auditing" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.auditing; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cloudfoundry/CloudFoundryCustomContextPathExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cloudfoundry/CloudFoundryCustomContextPathExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java index d1cbc15d5e45..7264c032dbdd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cloudfoundry/CloudFoundryCustomContextPathExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.cloudfoundry; +package org.springframework.boot.docs.productionreadyfeatures.cloudfoundry; +// tag::code[] import java.io.IOException; import java.util.Collections; @@ -36,15 +37,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for custom context path in Cloud Foundry. - * - * @author Johnny Lim - */ @Configuration(proxyBeanMethods = false) -public class CloudFoundryCustomContextPathExample { +public class CloudFoundryCustomContextPathConfiguration { - // tag::configuration[] @Bean public TomcatServletWebServerFactory servletWebServerFactory() { return new TomcatServletWebServerFactory() { @@ -65,7 +60,7 @@ protected void prepareContext(Host host, ServletContextInitializer[] initializer } private ServletContainerInitializer getServletContextInitializer(String contextPath) { - return (c, context) -> { + return (classes, context) -> { Servlet servlet = new GenericServlet() { @Override @@ -78,6 +73,6 @@ public void service(ServletRequest req, ServletResponse res) throws ServletExcep context.addServlet("cloudfoundry", servlet).addMapping("/*"); }; } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/package-info.java new file mode 100644 index 000000000000..07dedb276e0f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Cloud Foundry Support" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.cloudfoundry; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/enabling/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/enabling/package-info.java new file mode 100644 index 000000000000..038f7fb39b48 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/enabling/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Enabling Production Ready Features" + * section. + */ +package org.springframework.boot.docs.productionreadyfeatures.enabling; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/endpoint/CustomEndpointExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpoint.java similarity index 82% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/endpoint/CustomEndpointExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpoint.java index 78674d700ce5..b23bef3c3044 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/endpoint/CustomEndpointExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.endpoint; +package org.springframework.boot.docs.productionreadyfeatures.endpoints; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; -/** - * An example of a custom actuator endpoint. - * - * @author Stephane Nicoll - */ @Endpoint(id = "custom") -public class CustomEndpointExample { +public class CustomEndpoint { // tag::read[] @ReadOperation @@ -53,6 +48,14 @@ public CustomData(String name, int counter) { this.counter = counter; } + public String getName() { + return this.name; + } + + public int getCounter() { + return this.counter; + } + } } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/package-info.java new file mode 100644 index 000000000000..9f4ed9d93660 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Endpoints" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.endpoints; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/httptracing/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/httptracing/package-info.java new file mode 100644 index 000000000000..390de022b612 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/httptracing/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - HTTP Tracing" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.httptracing; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/loggers/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/loggers/package-info.java new file mode 100644 index 000000000000..bd125de90db2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/loggers/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Loggers" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.loggers; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsFilterBeanExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java similarity index 58% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsFilterBeanExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java index 3c7be0c394b8..b1d6e6335d7a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsFilterBeanExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,30 +14,21 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.metrics; +package org.springframework.boot.docs.productionreadyfeatures.metrics; +// tag::code[] import io.micrometer.core.instrument.config.MeterFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example to show a {@link MeterFilter}. - * - * @author Phillip Webb - */ -public class MetricsFilterBeanExample { - - @Configuration(proxyBeanMethods = false) - public static class MetricsFilterExampleConfiguration { - - // tag::configuration[] - @Bean - public MeterFilter renameRegionTagMeterFilter() { - return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area"); - } - // end::configuration[] +@Configuration(proxyBeanMethods = false) +public class MetricsFilterConfiguration { + @Bean + public MeterFilter renameRegionTagMeterFilter() { + return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area"); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsMeterRegistryInjectionExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java similarity index 51% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsMeterRegistryInjectionExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java index efb36a2e415c..093a7edac879 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/MetricsMeterRegistryInjectionExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,33 +14,38 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.metrics; +package org.springframework.boot.docs.productionreadyfeatures.metrics; +//tag::code[] +import java.util.Collections; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; -/** - * Example to show injection and use of a {@link MeterRegistry}. - * - * @author Andy Wilkinson - */ -public class MetricsMeterRegistryInjectionExample { +import org.springframework.stereotype.Component; - // tag::component[] - class Dictionary { +@Component +public class MetricsMeterRegistryInjection { - private final List words = new CopyOnWriteArrayList<>(); + private final Dictionary dictionary; - Dictionary(MeterRegistry registry) { - registry.gaugeCollectionSize("dictionary.size", Tags.empty(), this.words); - } + MetricsMeterRegistryInjection(MeterRegistry registry) { + this.dictionary = Dictionary.load(); + registry.gauge("dictionary.size", Tags.empty(), this.dictionary.getWords().size()); + } - // … +} +// end::code[] + +class Dictionary { + + static Dictionary load() { + return new Dictionary(); + } + List getWords() { + return Collections.emptyList(); } - // end::component[] } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/SampleMeterBinderConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java similarity index 74% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/SampleMeterBinderConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java index 63931823d7cf..18d28419d930 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuate/metrics/SampleMeterBinderConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,33 +14,28 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.metrics; +package org.springframework.boot.docs.productionreadyfeatures.metrics; +// tag::code[] import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.binder.MeterBinder; import org.springframework.context.annotation.Bean; -/** - * Example to show configuration of a custom {@link MeterBinder}. - * - * @author Andy Wilkinson - */ public class SampleMeterBinderConfiguration { - // tag::example[] @Bean MeterBinder queueSize(Queue queue) { return (registry) -> Gauge.builder("queueSize", queue::size).register(registry); } - // end::example[] - static class Queue { +} +// end::code[] - int size() { - return 5; - } +class Queue { + int size() { + return 5; } } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/package-info.java new file mode 100644 index 000000000000..0db6b7dd4eb4 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Metrics" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.metrics; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/http/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/http/package-info.java new file mode 100644 index 000000000000..b6856c0ea5f8 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/http/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Monitoring and Management overt HTTP" + * section. + */ +package org.springframework.boot.docs.productionreadyfeatures.monitoring.http; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/jmx/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/jmx/package-info.java new file mode 100644 index 000000000000..4f30dd6082ff --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/monitoring/jmx/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Monitoring and Management overt JMX" + * section. + */ +package org.springframework.boot.docs.productionreadyfeatures.monitoring.jmx; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/processmonitoring/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/processmonitoring/package-info.java new file mode 100644 index 000000000000..d785b52657e3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/processmonitoring/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Production Ready Features - Process Monitoring" section. + */ +package org.springframework.boot.docs.productionreadyfeatures.processmonitoring; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/caching/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/caching/package-info.java new file mode 100644 index 000000000000..ddc23dfa4ecf --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/caching/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Caching" section. + */ +package org.springframework.boot.docs.springbootfeatures.caching; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/containerimages/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/containerimages/package-info.java new file mode 100644 index 000000000000..9f29fcca7041 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/containerimages/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Container Images" section. + */ +package org.springframework.boot.docs.springbootfeatures.containerimages; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/package-info.java new file mode 100644 index 000000000000..07eacefd465f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Creating Your Own Auto-Configuration" section. + */ +package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/email/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/email/package-info.java new file mode 100644 index 000000000000..b6bca4cd16e7 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/email/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Sending Email" section. + */ +package org.springframework.boot.docs.springbootfeatures.email; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/ThirdPartyConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/ThirdPartyConfiguration.java new file mode 100644 index 000000000000..ee9d4ee8a18d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/ThirdPartyConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration; + +//tag::code[] +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class ThirdPartyConfiguration { + + @Bean + @ConfigurationProperties(prefix = "another") + public AnotherComponent anotherComponent() { + return new AnotherComponent(); + } + +} +// end::code[] + +class AnotherComponent { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/AcmeProperties.java new file mode 100644 index 000000000000..f5794c3653c7 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/AcmeProperties.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.constructorbinding; + +//tag::code[] +import java.net.InetAddress; +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.boot.context.properties.bind.DefaultValue; + +@ConstructorBinding +@ConfigurationProperties("acme") +public class AcmeProperties { + + private final boolean enabled; + + private final InetAddress remoteAddress; + + private final Security security; + + public AcmeProperties(boolean enabled, InetAddress remoteAddress, Security security) { + this.enabled = enabled; + this.remoteAddress = remoteAddress; + this.security = security; + } + + public boolean isEnabled() { + return this.enabled; + } + + public InetAddress getRemoteAddress() { + return this.remoteAddress; + } + + public Security getSecurity() { + return this.security; + } + + public static class Security { + + private final String username; + + private final String password; + + private final List roles; + + public Security(String username, String password, @DefaultValue("USER") List roles) { + this.username = username; + this.password = password; + this.roles = roles; + } + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + + public List getRoles() { + return this.roles; + } + + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/nonnull/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/nonnull/AcmeProperties.java new file mode 100644 index 000000000000..19aaf5ff87e1 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/constructorbinding/nonnull/AcmeProperties.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.constructorbinding.nonnull; + +import java.net.InetAddress; +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.boot.context.properties.bind.DefaultValue; + +@ConstructorBinding +@ConfigurationProperties("acme") +public class AcmeProperties { + + private final boolean enabled; + + private final InetAddress remoteAddress; + + private final Security security; + + // tag::code[] + public AcmeProperties(boolean enabled, InetAddress remoteAddress, @DefaultValue Security security) { + this.enabled = enabled; + this.remoteAddress = remoteAddress; + this.security = security; + } + // end::code[] + + public boolean isEnabled() { + return this.enabled; + } + + public InetAddress getRemoteAddress() { + return this.remoteAddress; + } + + public Security getSecurity() { + return this.security; + } + + public static class Security { + + private final String username; + + private final String password; + + private final List roles; + + public Security(String username, String password, @DefaultValue("USER") List roles) { + this.username = username; + this.password = password; + this.roles = roles; + } + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + + public List getRoles() { + return this.roles; + } + + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppIoProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java similarity index 82% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppIoProperties.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java index 86bcb9e76a55..ea1b16249e18 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppIoProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.constructor; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.constructorbinding; +// tag::code[] import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.bind.DefaultValue; @@ -23,13 +24,6 @@ import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link DataSize}. - * - * @author Stephane Nicoll - */ -// tag::example[] @ConfigurationProperties("app.io") @ConstructorBinding public class AppIoProperties { @@ -53,4 +47,4 @@ public DataSize getSizeThreshold() { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppIoProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java similarity index 81% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppIoProperties.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java index 15862ff55f48..c69b097d7016 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppIoProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.javabean; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.javabeanbinding; +// tag::code[] import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DataSizeUnit; import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link DataSize}. - * - * @author Stephane Nicoll - */ -// tag::example[] @ConfigurationProperties("app.io") public class AppIoProperties { @@ -53,4 +47,4 @@ public void setSizeThreshold(DataSize sizeThreshold) { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java similarity index 82% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemProperties.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java index d30b635c839c..bdfb5a3bb64d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.constructor; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.constructorbinding; +// tag::code[] import java.time.Duration; import java.time.temporal.ChronoUnit; @@ -24,13 +25,6 @@ import org.springframework.boot.context.properties.bind.DefaultValue; import org.springframework.boot.convert.DurationUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link Duration}. - * - * @author Stephane Nicoll - */ -// tag::example[] @ConfigurationProperties("app.system") @ConstructorBinding public class AppSystemProperties { @@ -54,4 +48,4 @@ public Duration getReadTimeout() { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java similarity index 81% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemProperties.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java index eca2bb440719..9aabcd46ecdb 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,15 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.javabean; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.javabeanbinding; +// tag::code[] import java.time.Duration; import java.time.temporal.ChronoUnit; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DurationUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link Duration}. - * - * @author Stephane Nicoll - */ -// tag::example[] @ConfigurationProperties("app.system") public class AppSystemProperties { @@ -54,4 +48,4 @@ public void setReadTimeout(Duration readTimeout) { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyApplication.java new file mode 100644 index 000000000000..9e41e9e65b8b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyApplication.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.enable; + +//tag::code[] +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; + +@SpringBootApplication +@ConfigurationPropertiesScan({ "com.example.app", "org.acme.another" }) +public class MyApplication { + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyConfiguration.java new file mode 100644 index 000000000000..41d624a8d90f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/enable/MyConfiguration.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.enable; + +//tag::code[] +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties(AcmeProperties.class) +public class MyConfiguration { + +} +// end::code[] + +class AcmeProperties { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/javabeanbinding/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/javabeanbinding/AcmeProperties.java new file mode 100644 index 000000000000..a994f5de38ca --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/javabeanbinding/AcmeProperties.java @@ -0,0 +1,91 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.javabeanbinding; + +//tag::code[] +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("acme") +public class AcmeProperties { + + private boolean enabled; + + private InetAddress remoteAddress; + + private final Security security = new Security(); + + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public InetAddress getRemoteAddress() { + return this.remoteAddress; + } + + public void setRemoteAddress(InetAddress remoteAddress) { + this.remoteAddress = remoteAddress; + } + + public Security getSecurity() { + return this.security; + } + + public static class Security { + + private String username; + + private String password; + + private List roles = new ArrayList<>(Collections.singleton("USER")); + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public List getRoles() { + return this.roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/list/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/list/AcmeProperties.java new file mode 100644 index 000000000000..7419f33d00bc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/list/AcmeProperties.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.merge.list; + +//tag::code[] +import java.util.ArrayList; +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("acme") +public class AcmeProperties { + + private final List list = new ArrayList<>(); + + public List getList() { + return this.list; + } + +} +// end::code[] + +class MyPojo { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/map/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/map/AcmeProperties.java new file mode 100644 index 000000000000..250d1c44dca2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/merge/map/AcmeProperties.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.merge.map; + +//tag::code[] +import java.util.LinkedHashMap; +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("acme") +public class AcmeProperties { + + private final Map map = new LinkedHashMap<>(); + + public Map getMap() { + return this.map; + } + +} +// end::code[] + +class MyPojo { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/package-info.java new file mode 100644 index 000000000000..7a663f72c9ef --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Externalized Configuration" section. + */ +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/relaxed/OwnerProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/relaxed/OwnerProperties.java new file mode 100644 index 000000000000..0ebc6f17d813 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/relaxed/OwnerProperties.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.relaxed; + +//tag::code[] +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "acme.my-project.person") +public class OwnerProperties { + + private String firstName; + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/use/MyService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/use/MyService.java new file mode 100644 index 000000000000..d6d74c52acca --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/use/MyService.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.use; + +//tag::code[] +import org.springframework.stereotype.Service; + +@Service +public class MyService { + + private final AcmeProperties properties; + + public MyService(AcmeProperties properties) { + this.properties = properties; + } + + public void openConnection() { + Server server = new Server(this.properties.getRemoteAddress()); + server.start(); + // ... + } + + // ... + +} +// end::code[] + +class AcmeProperties { + + Object getRemoteAddress() { + return null; + } + +} + +class Server { + + Server(Object remoteAddress) { + } + + void start() { + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/AcmeProperties.java new file mode 100644 index 000000000000..da5b5133a4cd --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/AcmeProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.validate; + +//tag::code[] +import java.net.InetAddress; + +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +@ConfigurationProperties(prefix = "acme") +@Validated +public class AcmeProperties { + + @NotNull + private InetAddress remoteAddress; + + public InetAddress getRemoteAddress() { + return this.remoteAddress; + } + + public void setRemoteAddress(InetAddress remoteAddress) { + this.remoteAddress = remoteAddress; + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/nested/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/nested/AcmeProperties.java new file mode 100644 index 000000000000..4e71fec39adc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/validate/nested/AcmeProperties.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.validate.nested; + +//tag::code[] +import java.net.InetAddress; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +@ConfigurationProperties(prefix = "acme") +@Validated +public class AcmeProperties { + + @NotNull + private InetAddress remoteAddress; + + @Valid + private final Security security = new Security(); + + public InetAddress getRemoteAddress() { + return this.remoteAddress; + } + + public void setRemoteAddress(InetAddress remoteAddress) { + this.remoteAddress = remoteAddress; + } + + public Security getSecurity() { + return this.security; + } + + public static class Security { + + @NotEmpty + private String username; + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/valueinjection/MyBean.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/valueinjection/MyBean.java new file mode 100644 index 000000000000..f2a388ca71e8 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/valueinjection/MyBean.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.valueinjection; + +// tag::code[] +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class MyBean { + + @Value("${name}") + private String name; + + // ... + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/gracefulshutdown/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/gracefulshutdown/package-info.java new file mode 100644 index 000000000000..6d9a551294c1 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/gracefulshutdown/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Graceful Shutdown" section. + */ +package org.springframework.boot.docs.springbootfeatures.gracefulshutdown; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/hazelcast/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/hazelcast/package-info.java new file mode 100644 index 000000000000..a3b310c68bef --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/hazelcast/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Hazelcast" section. + */ +package org.springframework.boot.docs.springbootfeatures.hazelcast; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/integration/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/integration/package-info.java new file mode 100644 index 000000000000..24ed40f48ca0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/integration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Spring Integration" section. + */ +package org.springframework.boot.docs.springbootfeatures.integration; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/internationalization/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/internationalization/package-info.java new file mode 100644 index 000000000000..24086edc3b99 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/internationalization/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Internationalization" section. + */ +package org.springframework.boot.docs.springbootfeatures.internationalization; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/json/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/json/package-info.java new file mode 100644 index 000000000000..6ed366df90c8 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/json/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - JSON" section. + */ +package org.springframework.boot.docs.springbootfeatures.json; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/jta/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/jta/package-info.java new file mode 100644 index 000000000000..ccd988187212 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/jta/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Distributed Transactions with JTA" section. + */ +package org.springframework.boot.docs.springbootfeatures.jta; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/kotlin/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/kotlin/package-info.java new file mode 100644 index 000000000000..ff3d203b9de9 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/kotlin/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Kotlin" section. + */ +package org.springframework.boot.docs.springbootfeatures.kotlin; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/logging/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/logging/package-info.java new file mode 100644 index 000000000000..e8ea52187db0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/logging/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Logging" section. + */ +package org.springframework.boot.docs.springbootfeatures.logging; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/kafka/KafkaStreamsBeanExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java similarity index 60% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/kafka/KafkaStreamsBeanExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java index ebad610febf7..2a4dbdd3055c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/kafka/KafkaStreamsBeanExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.kafka; +package org.springframework.boot.docs.springbootfeatures.messaging; +// tag::code[] import org.apache.kafka.common.serialization.Serdes; import org.apache.kafka.streams.KeyValue; import org.apache.kafka.streams.StreamsBuilder; @@ -27,27 +28,17 @@ import org.springframework.kafka.annotation.EnableKafkaStreams; import org.springframework.kafka.support.serializer.JsonSerde; -/** - * Example to show usage of {@link StreamsBuilder}. - * - * @author Stephane Nicoll - */ -public class KafkaStreamsBeanExample { - - // tag::configuration[] - @Configuration(proxyBeanMethods = false) - @EnableKafkaStreams - public static class KafkaStreamsExampleConfiguration { - - @Bean - public KStream kStream(StreamsBuilder streamsBuilder) { - KStream stream = streamsBuilder.stream("ks1In"); - stream.map((k, v) -> new KeyValue<>(k, v.toUpperCase())).to("ks1Out", - Produced.with(Serdes.Integer(), new JsonSerde<>())); - return stream; - } +@Configuration(proxyBeanMethods = false) +@EnableKafkaStreams +public class KafkaStreamsConfiguration { + @Bean + public KStream kStream(StreamsBuilder streamsBuilder) { + KStream stream = streamsBuilder.stream("ks1In"); + stream.map((k, v) -> new KeyValue<>(k, v.toUpperCase())).to("ks1Out", + Produced.with(Serdes.Integer(), new JsonSerde<>())); + return stream; } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/package-info.java new file mode 100644 index 000000000000..e90952c4743b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Messaging" section. + */ +package org.springframework.boot.docs.springbootfeatures.messaging; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/monitoring/jmx/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/monitoring/jmx/package-info.java new file mode 100644 index 000000000000..9f29cd5082c6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/monitoring/jmx/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Monitoring with JMX" section. + */ +package org.springframework.boot.docs.springbootfeatures.monitoring.jmx; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/CouchbaseCacheManagerCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/CouchbaseCacheManagerCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java index 612a955c2c2d..e130e09ce4fd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/CouchbaseCacheManagerCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.cache; +package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.cache.CouchbaseCacheManagerBuilderCustomizer; @@ -23,16 +24,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration; -/** - * An example how to customize {@code CouchbaseCacheManagerBuilder} via - * {@code CouchbaseCacheManagerBuilderCustomizer}. - * - * @author Dmytro Nosan - */ @Configuration(proxyBeanMethods = false) -public class CouchbaseCacheManagerCustomizationExample { +public class CouchbaseCacheManagerConfiguration { - // tag::configuration[] @Bean public CouchbaseCacheManagerBuilderCustomizer myCouchbaseCacheManagerBuilderCustomizer() { return (builder) -> builder @@ -42,6 +36,6 @@ public CouchbaseCacheManagerBuilderCustomizer myCouchbaseCacheManagerBuilderCust CouchbaseCacheConfiguration.defaultCacheConfig().entryExpiry(Duration.ofMinutes(1))); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/neo4j/Neo4jReactiveTransactionManagerExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java similarity index 74% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/neo4j/Neo4jReactiveTransactionManagerExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java index 81a95ce5d674..34ef8f4f5ed8 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/neo4j/Neo4jReactiveTransactionManagerExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,30 +14,24 @@ * limitations under the License. */ -package org.springframework.boot.docs.neo4j; +package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import org.neo4j.driver.Driver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.neo4j.core.ReactiveDatabaseSelectionProvider; import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager; -import org.springframework.transaction.ReactiveTransactionManager; -/** - * Example to show user-defined registration of a {@link ReactiveTransactionManager}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class Neo4jReactiveTransactionManagerExample { +public class Neo4jReactiveTransactionManagerConfiguration { - // tag::configuration[] @Bean public ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver, ReactiveDatabaseSelectionProvider databaseNameProvider) { return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/RedisCacheManagerCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/RedisCacheManagerCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java index 88f56fa93d86..d3b0b9780426 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/RedisCacheManagerCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.cache; +package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer; @@ -23,16 +24,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; -/** - * An example how to customize {@code RedisCacheManagerBuilder} via - * {@code RedisCacheManagerBuilderCustomizer}. - * - * @author Dmytro Nosan - */ @Configuration(proxyBeanMethods = false) -public class RedisCacheManagerCustomizationExample { +public class RedisCacheManagerConfiguration { - // tag::configuration[] @Bean public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() { return (builder) -> builder @@ -42,6 +36,6 @@ public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(1))); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/package-info.java new file mode 100644 index 000000000000..3602d3951901 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Working with NoSQL Technologies" section. + */ +package org.springframework.boot.docs.springbootfeatures.nosql; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/ProductionConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/ProductionConfiguration.java new file mode 100644 index 000000000000..4317d6faf4ef --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/ProductionConfiguration.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.profiles; + +//tag::code[] +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration(proxyBeanMethods = false) +@Profile("production") +public class ProductionConfiguration { + + // ... + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/package-info.java new file mode 100644 index 000000000000..9f29878c134f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/profiles/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Profiles" section. + */ +package org.springframework.boot.docs.springbootfeatures.profiles; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/quartz/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/quartz/package-info.java new file mode 100644 index 000000000000..201bb165a3d0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/quartz/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Quartz" section. + */ +package org.springframework.boot.docs.springbootfeatures.quartz; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateBuilderCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java similarity index 75% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateBuilderCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java index d67e4328a667..7ad9628e7f7b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateBuilderCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.client; +package org.springframework.boot.docs.springbootfeatures.resttemplate; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.web.client.RestTemplateBuilderConfigurer; @@ -23,21 +24,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for using a {@link RestTemplateBuilderConfigurer} to configure a - * custom {@link RestTemplateBuilder}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class RestTemplateBuilderCustomizationExample { +public class RestTemplateBuilderConfiguration { - // tag::customizer[] @Bean public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) { return configurer.configure(new RestTemplateBuilder()).setConnectTimeout(Duration.ofSeconds(5)) .setReadTimeout(Duration.ofSeconds(2)); } - // end::customizer[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java new file mode 100644 index 000000000000..37a06cb232a2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.resttemplate; + +// tag::code[] +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.routing.HttpRoutePlanner; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.DefaultProxyRoutePlanner; +import org.apache.http.protocol.HttpContext; + +import org.springframework.boot.web.client.RestTemplateCustomizer; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +public class RestTemplateProxyCustomizer implements RestTemplateCustomizer { + + @Override + public void customize(RestTemplate restTemplate) { + HttpRoutePlanner routePlanner = new CustomRoutePlanner(new HttpHost("proxy.example.com")); + HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(routePlanner).build(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + } + + static class CustomRoutePlanner extends DefaultProxyRoutePlanner { + + CustomRoutePlanner(HttpHost proxy) { + super(proxy); + } + + @Override + public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { + if (target.getHostName().equals("192.168.0.5")) { + return null; + } + return super.determineProxy(target, request, context); + } + + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/package-info.java new file mode 100644 index 000000000000..7fd33321fcea --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Calling REST Services with RestTemplate" + * section. + */ +package org.springframework.boot.docs.springbootfeatures.resttemplate; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/rsocket/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/rsocket/package-info.java new file mode 100644 index 000000000000..abb639471647 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/rsocket/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - RSocket" section. + */ +package org.springframework.boot.docs.springbootfeatures.rsocket; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/security/CustomWebFluxSecurityExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java similarity index 64% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/security/CustomWebFluxSecurityExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java index 9db671e57ec8..219e8feb9007 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/security/CustomWebFluxSecurityExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,35 +14,27 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.security; +package org.springframework.boot.docs.springbootfeatures.security; +// tag::code[] import org.springframework.boot.autoconfigure.security.reactive.PathRequest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; -/** - * Example configuration for customizing security rules for a WebFlux application. - * - * @author Madhura Bhave - */ @Configuration(proxyBeanMethods = false) -public class CustomWebFluxSecurityExample { +public class CustomWebFluxSecurityConfiguration { - // @formatter:off - // tag::configuration[] @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - return http - .authorizeExchange() - .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() - .pathMatchers("/foo", "/bar") - .authenticated().and() - .formLogin().and() - .build(); + http.authorizeExchange((spec) -> { + spec.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll(); + spec.pathMatchers("/foo", "/bar").authenticated(); + }); + http.formLogin(); + return http.build(); } - // end::configuration[] - // @formatter:on } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/package-info.java new file mode 100644 index 000000000000..b2aa6cd5e0b0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Security" section. + */ +package org.springframework.boot.docs.springbootfeatures.security; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/session/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/session/package-info.java new file mode 100644 index 000000000000..e0b0be983452 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/session/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Spring Session" section. + */ +package org.springframework.boot.docs.springbootfeatures.session; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ApplicationArgumentsExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ApplicationArgumentsExample.java new file mode 100644 index 000000000000..55d895f82623 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ApplicationArgumentsExample.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication; + +//tag::code[] +import java.util.List; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.stereotype.Component; + +@Component +public class ApplicationArgumentsExample { + + public ApplicationArgumentsExample(ApplicationArguments args) { + boolean debug = args.containsOption("debug"); + List files = args.getNonOptionArgs(); + if (debug) { + System.out.println(files); + } + // if run with "--debug logfile.txt" prints ["logfile.txt"] + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/CommandLineRunnerExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/CommandLineRunnerExample.java new file mode 100644 index 000000000000..e082045d67d2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/CommandLineRunnerExample.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication; + +//tag::code[] +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class CommandLineRunnerExample implements CommandLineRunner { + + @Override + public void run(String... args) { + // Do something... + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java similarity index 75% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java index d1944fff70bb..84220a91446f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,40 +14,29 @@ * limitations under the License. */ -package org.springframework.boot.docs.builder; +package org.springframework.boot.docs.springbootfeatures.springapplication; import org.springframework.boot.Banner; import org.springframework.boot.builder.SpringApplicationBuilder; -/** - * Examples of using {@link SpringApplicationBuilder}. - * - * @author Andy Wilkinson - */ public class SpringApplicationBuilderExample { public void hierarchyWithDisabledBanner(String[] args) { // @formatter:off - // tag::hierarchy[] + // tag::code[] new SpringApplicationBuilder() .sources(Parent.class) .child(Application.class) .bannerMode(Banner.Mode.OFF) .run(args); - // end::hierarchy[] + // end::code[] // @formatter:on } - /** - * Parent application configuration. - */ static class Parent { } - /** - * Application configuration. - */ static class Application { } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/LocalCacheVerifier.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/LocalCacheVerifier.java new file mode 100644 index 000000000000..1fd7fbb4064d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/LocalCacheVerifier.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication.availability; + +//tag::code[] +import org.springframework.boot.availability.AvailabilityChangeEvent; +import org.springframework.boot.availability.LivenessState; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +@Component +public class LocalCacheVerifier { + + private final ApplicationEventPublisher eventPublisher; + + public LocalCacheVerifier(ApplicationEventPublisher eventPublisher) { + this.eventPublisher = eventPublisher; + } + + public void checkLocalCache() { + try { + // ... + } + catch (CacheCompletelyBrokenException ex) { + AvailabilityChangeEvent.publish(this.eventPublisher, ex, LivenessState.BROKEN); + } + } + +} +// end::code[] + +class CacheCompletelyBrokenException extends RuntimeException { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/ReadinessStateExporter.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/ReadinessStateExporter.java new file mode 100644 index 000000000000..4b82ecf8d31d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/availability/ReadinessStateExporter.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication.availability; + +// tag::code[] +import org.springframework.boot.availability.AvailabilityChangeEvent; +import org.springframework.boot.availability.ReadinessState; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +public class ReadinessStateExporter { + + @EventListener + public void onStateChange(AvailabilityChangeEvent event) { + switch (event.getState()) { + case ACCEPTING_TRAFFIC: + // create file /tmp/healthy + break; + case REFUSING_TRAFFIC: + // remove file /tmp/healthy + break; + } + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/ExitCodeApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/exitcode/MyApplication.java similarity index 71% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/ExitCodeApplication.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/exitcode/MyApplication.java index 813c6ed09283..aedb4ff14de9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/ExitCodeApplication.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/exitcode/MyApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.docs; +package org.springframework.boot.docs.springbootfeatures.springapplication.exitcode; +// tag::code[] import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -/** - * Example configuration that illustrates the use of {@link ExitCodeGenerator}. - * - * @author Stephane Nicoll - */ -// tag::example[] @SpringBootApplication -public class ExitCodeApplication { +public class MyApplication { @Bean public ExitCodeGenerator exitCodeGenerator() { @@ -36,8 +31,8 @@ public ExitCodeGenerator exitCodeGenerator() { } public static void main(String[] args) { - System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeApplication.class, args))); + System.exit(SpringApplication.exit(SpringApplication.run(MyApplication.class, args))); } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/custom/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/custom/MyApplication.java new file mode 100644 index 000000000000..40f8f32e3f9f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/custom/MyApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication.main.custom; + +import org.springframework.boot.Banner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyApplication { + + // tag::code[] + public static void main(String[] args) { + SpringApplication application = new SpringApplication(MyApplication.class); + application.setBannerMode(Banner.Mode.OFF); + application.run(args); + } + // end::code[] + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/run/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/run/MyApplication.java new file mode 100644 index 000000000000..07d9b0ceffed --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/main/run/MyApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication.main.run; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyApplication { + + // tag::code[] + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + // end::code[] + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/package-info.java new file mode 100644 index 000000000000..2af4c750ba93 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - SpringApplication" section. + */ +package org.springframework.boot.docs.springbootfeatures.springapplication; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/startup/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/startup/MyApplication.java new file mode 100644 index 000000000000..5df88e11ad95 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/startup/MyApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.springapplication.startup; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; + +@SpringBootApplication +public class MyApplication { + + // tag::code[] + public static void main(String[] args) { + SpringApplication application = new SpringApplication(MyApplication.class); + application.setApplicationStartup(new BufferingApplicationStartup(2048)); + application.run(args); + } + // end::code[] + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/sql/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/sql/package-info.java new file mode 100644 index 000000000000..9aad26329e1e --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/sql/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Working with SQL Databases" section. + */ +package org.springframework.boot.docs.springbootfeatures.sql; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/task/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/task/package-info.java new file mode 100644 index 000000000000..ee9d79667414 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/task/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Task Execution and Scheduling" section. + */ +package org.springframework.boot.docs.springbootfeatures.task; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/context/ApplicationArgumentsExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/context/ApplicationArgumentsExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java index 79625817166c..620cbad89ec0 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/context/ApplicationArgumentsExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.context; +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -24,9 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat; -// tag::example[] @SpringBootTest(args = "--app.test=one") -class ApplicationArgumentsExampleTests { +class ApplicationArgumentTests { @Test void applicationArgumentsPopulated(@Autowired ApplicationArguments args) { @@ -35,4 +35,4 @@ void applicationArgumentsPopulated(@Autowired ApplicationArguments args) { } } -// end::example[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockMvcExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockMvcExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java index e6e6738363ed..513a85336d7c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockMvcExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.web; - -// tag::test-mock-mvc[] +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +30,7 @@ @SpringBootTest @AutoConfigureMockMvc -class MockMvcExampleTests { +class MockMvcTests { @Test void exampleTest(@Autowired MockMvc mvc) throws Exception { @@ -39,4 +38,4 @@ void exampleTest(@Autowired MockMvc mvc) throws Exception { } } -// end::test-mock-mvc[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockWebTestClientExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java similarity index 83% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockWebTestClientExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java index 883f5ebd3822..4a1ae58c0fb5 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/MockWebTestClientExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.web; - -// tag::test-mock-web-test-client[] +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,7 @@ @SpringBootTest @AutoConfigureWebTestClient -class MockWebTestClientExampleTests { +class MockWebTestClientTests { @Test void exampleTest(@Autowired WebTestClient webClient) { @@ -35,4 +34,4 @@ void exampleTest(@Autowired WebTestClient webClient) { } } -// end::test-mock-web-test-client[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/test/system/OutputCaptureTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java similarity index 81% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/test/system/OutputCaptureTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java index 8f9a3731fcee..bd5989d9a4ed 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/test/system/OutputCaptureTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.system; +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -24,12 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat; -/** - * Sample showcasing the use of {@link CapturedOutput}. - * - * @author Stephane Nicoll - */ -// tag::test[] @ExtendWith(OutputCaptureExtension.class) class OutputCaptureTests { @@ -40,4 +35,4 @@ void testName(CapturedOutput output) { } } -// end::test[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortTestRestTemplateExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortTestRestTemplateExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java index 32a93ad3d10c..3ba15b7e1d35 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortTestRestTemplateExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.web; - -// tag::test-random-port[] +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class RandomPortTestRestTemplateExampleTests { +class RandomPortTestRestTemplateTests { @Test void exampleTest(@Autowired TestRestTemplate restTemplate) { @@ -37,4 +36,4 @@ void exampleTest(@Autowired TestRestTemplate restTemplate) { } } -// end::test-random-port[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortWebTestClientExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java similarity index 84% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortWebTestClientExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java index 9a800a3f3e46..60ff61d2efd5 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/web/RandomPortWebTestClientExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.web; - -// tag::test-random-port[] +package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +25,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class RandomPortWebTestClientExampleTests { +class RandomPortWebTestClientTests { @Test void exampleTest(@Autowired WebTestClient webClient) { @@ -34,4 +33,4 @@ void exampleTest(@Autowired WebTestClient webClient) { } } -// end::test-random-port[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java similarity index 81% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserService.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java index 4b089ca29ba8..edc4e8363c20 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserService.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,8 @@ * limitations under the License. */ -package org.springframework.boot.docs.autoconfigure; +package org.springframework.boot.docs.springbootfeatures.testing; -/** - * Sample service. - * - * @author Stephane Nicoll - */ public class UserService { private final String name; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java index 7566b78ad5c2..e84412028481 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.docs.autoconfigure; +package org.springframework.boot.docs.springbootfeatures.testing; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.docs.autoconfigure.UserServiceAutoConfiguration.UserProperties; +import org.springframework.boot.docs.springbootfeatures.testing.UserServiceAutoConfiguration.UserProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Sample auto-configuration. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(UserService.class) @EnableConfigurationProperties(UserProperties.class) diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfigurationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java similarity index 92% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfigurationTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java index ddff07b9cf01..3250a45467c0 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/autoconfigure/UserServiceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.autoconfigure; +package org.springframework.boot.docs.springbootfeatures.testing; import org.junit.jupiter.api.Test; @@ -26,11 +26,6 @@ import static org.assertj.core.api.Assertions.assertThat; -/** - * Tests for {@link UserServiceAutoConfiguration}. - * - * @author Stephane Nicoll - */ class UserServiceAutoConfigurationTests { // tag::runner[] diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleApp.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java similarity index 77% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleApp.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java index ea5ecad61ff7..0edc242b2f01 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleApp.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,12 @@ * limitations under the License. */ -package org.springframework.boot.docs.jmx; +package org.springframework.boot.docs.springbootfeatures.testing.jmx; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -/** - * A sample {@link SpringBootConfiguration @ConfigurationProperties} that only enables JMX - * auto-configuration. - * - * @author Stephane Nicoll - */ @SpringBootConfiguration @ImportAutoConfiguration(JmxAutoConfiguration.class) public class SampleApp { diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleJmxTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java similarity index 74% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleJmxTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java index c469e6daa32e..74e695e3973c 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jmx/SampleJmxTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,11 @@ * limitations under the License. */ -package org.springframework.boot.docs.jmx; +package org.springframework.boot.docs.springbootfeatures.testing.jmx; +// tag::code[] import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -26,13 +28,8 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; -/** - * Example integration test that uses JMX. - * - * @author Stephane Nicoll - */ -@SuppressWarnings("unused") -// tag::test[] +import static org.assertj.core.api.Assertions.assertThat; + @ExtendWith(SpringExtension.class) @SpringBootTest(properties = "spring.jmx.enabled=true") @DirtiesContext @@ -42,9 +39,10 @@ class SampleJmxTests { private MBeanServer mBeanServer; @Test - void exampleTest() { + void exampleTest() throws MalformedObjectNameException { + assertThat(this.mBeanServer.getDomains()).contains("java.lang"); // ... } } -// end::test[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/package-info.java new file mode 100644 index 000000000000..e499e9d77ac0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Testing" section. + */ +package org.springframework.boot.docs.springbootfeatures.testing; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/AdvancedConfigurationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java similarity index 62% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/AdvancedConfigurationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java index 1e3247b893fc..11bd10590671 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/AdvancedConfigurationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,21 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.autoconfigure.restdocs.restassured; +package org.springframework.boot.docs.springbootfeatures.testing.restdocs.restassured; +// tag::code[] import org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.restdocs.restassured3.RestAssuredRestDocumentationConfigurer; import org.springframework.restdocs.templates.TemplateFormats; -public class AdvancedConfigurationExample { - - // tag::configuration[] - @TestConfiguration(proxyBeanMethods = false) - public static class CustomizationConfiguration implements RestDocsRestAssuredConfigurationCustomizer { - - @Override - public void customize(RestAssuredRestDocumentationConfigurer configurer) { - configurer.snippets().withTemplateFormat(TemplateFormats.markdown()); - } +@TestConfiguration(proxyBeanMethods = false) +public class AdvancedRestDocsConfiguration implements RestDocsRestAssuredConfigurationCustomizer { + @Override + public void customize(RestAssuredRestDocumentationConfigurer configurer) { + configurer.snippets().withTemplateFormat(TemplateFormats.markdown()); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/UserDocumentationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/UserDocumentationTests.java similarity index 89% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/UserDocumentationTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/UserDocumentationTests.java index 84f2ec13230d..b2e48aac4e5a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/restassured/UserDocumentationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/UserDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.autoconfigure.restdocs.restassured; +package org.springframework.boot.docs.springbootfeatures.testing.restdocs.restassured; -// tag::source[] +// tag::code[] import io.restassured.specification.RequestSpecification; import org.junit.jupiter.api.Test; @@ -41,4 +41,4 @@ void listUsers(@Autowired RequestSpecification documentationSpec, @LocalServerPo } } -// end::source[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java similarity index 61% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java index a5b574a59dcb..16ca58f24673 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,20 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient; +package org.springframework.boot.docs.springbootfeatures.testing.restdocs.webclient; +// tag::code[] import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer; -public class AdvancedConfigurationExample { - - // tag::configuration[] - @TestConfiguration(proxyBeanMethods = false) - public static class CustomizationConfiguration implements RestDocsWebTestClientConfigurationCustomizer { - - @Override - public void customize(WebTestClientRestDocumentationConfigurer configurer) { - configurer.snippets().withEncoding("UTF-8"); - } +@TestConfiguration(proxyBeanMethods = false) +public class AdvancedRestDocsConfiguration implements RestDocsWebTestClientConfigurationCustomizer { + @Override + public void customize(WebTestClientRestDocumentationConfigurer configurer) { + configurer.snippets().withEncoding("UTF-8"); } - // end::configuration[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/UsersDocumentationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/UsersDocumentationTests.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/UsersDocumentationTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/UsersDocumentationTests.java index 7f06bc090c13..f6ebbdb3c612 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/test/autoconfigure/restdocs/webclient/UsersDocumentationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/UsersDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient; +package org.springframework.boot.docs.springbootfeatures.testing.restdocs.webclient; -// tag::source[] +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -40,4 +40,4 @@ void listUsers() { } } -// end::source[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java similarity index 87% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java index f96e46538bac..099f5ae35095 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.client; +package org.springframework.boot.docs.springbootfeatures.testing.webclient; import java.net.URI; @@ -28,12 +28,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -/** - * A sample {@link SpringBootConfiguration @ConfigurationProperties} with an example - * controller. - * - * @author Stephane Nicoll - */ @SpringBootConfiguration @ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java similarity index 87% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java index 117b892a3bda..d5535f4cf036 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/web/client/SampleWebClientTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.client; +package org.springframework.boot.docs.springbootfeatures.testing.webclient; +// tag::code[] import java.time.Duration; import org.junit.jupiter.api.Test; @@ -31,12 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat; -/** - * Example integration test that uses {@link TestRestTemplate}. - * - * @author Stephane Nicoll - */ -// tag::test[] @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class SampleWebClientTests { @@ -50,7 +45,7 @@ void testRequest() { } @TestConfiguration(proxyBeanMethods = false) - static class Config { + static class RestTemplateBuilderConfiguration { @Bean RestTemplateBuilder restTemplateBuilder() { @@ -61,4 +56,4 @@ RestTemplateBuilder restTemplateBuilder() { } } -// end::test[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/validation/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/validation/package-info.java new file mode 100644 index 000000000000..16b4e55655b7 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/validation/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Validation" section. + */ +package org.springframework.boot.docs.springbootfeatures.validation; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/HttpMessageConvertersConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/HttpMessageConvertersConfiguration.java new file mode 100644 index 000000000000..84aae404e655 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/HttpMessageConvertersConfiguration.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications; + +//tag::code[] +import java.io.IOException; + +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.converter.AbstractHttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; + +@Configuration(proxyBeanMethods = false) +public class HttpMessageConvertersConfiguration { + + @Bean + public HttpMessageConverters customConverters() { + HttpMessageConverter additional = new AdditionalHttpMessageConverter(); + HttpMessageConverter another = new AnotherHttpMessageConverter(); + return new HttpMessageConverters(additional, another); + } + +} +// end::code[] + +class AdditionalHttpMessageConverter extends AbstractHttpMessageConverter { + + @Override + protected boolean supports(Class clazz) { + return false; + } + + @Override + protected Object readInternal(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return null; + } + + @Override + protected void writeInternal(Object t, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + } + +} + +class AnotherHttpMessageConverter extends AdditionalHttpMessageConverter { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatServerCustomizerExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java similarity index 66% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatServerCustomizerExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java index 6e17bb63acbe..49cbd9a0fb12 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/context/embedded/TomcatServerCustomizerExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java @@ -14,28 +14,22 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.springbootfeatures.webapplications; +// tag::code[] import java.time.Duration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.stereotype.Component; -/** - * Example of a {@link WebServerFactoryCustomizer} that uses a more narrowed server type. - * - * @author Stephane Nicoll - */ -// tag::configuration[] @Component -public class TomcatServerCustomizerExample implements WebServerFactoryCustomizer { +public class TomcatServerCustomizer implements WebServerFactoryCustomizer { @Override public void customize(TomcatServletWebServerFactory server) { - server.addConnectorCustomizers( - (tomcatConnector) -> tomcatConnector.setAsyncTimeout(Duration.ofSeconds(20).toMillis())); + server.addConnectorCustomizers((connector) -> connector.setAsyncTimeout(Duration.ofSeconds(20).toMillis())); } } -// end::configuration[] +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/MyJsonComponent.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/MyJsonComponent.java new file mode 100644 index 000000000000..e610051f1963 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/MyJsonComponent.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.json; + +//tag::code[] +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import org.springframework.boot.jackson.JsonComponent; + +@JsonComponent +public class MyJsonComponent { + + public static class Serializer extends JsonSerializer { + + @Override + public void serialize(MyObject value, JsonGenerator jgen, SerializerProvider serializers) throws IOException { + jgen.writeStringField("name", value.getName()); + jgen.writeNumberField("age", value.getAge()); + } + + } + + public static class Deserializer extends JsonDeserializer { + + @Override + public MyObject deserialize(JsonParser jsonParser, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + ObjectCodec codec = jsonParser.getCodec(); + JsonNode tree = codec.readTree(jsonParser); + String name = tree.get("name").textValue(); + int age = tree.get("age").intValue(); + return new MyObject(name, age); + } + + } + +} +// end::code[] + +class MyObject { + + MyObject(String name, int age) { + } + + String getName() { + return null; + } + + Integer getAge() { + return null; + + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/object/MyJsonComponent.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/object/MyJsonComponent.java new file mode 100644 index 000000000000..cd2a062f9b9e --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/json/object/MyJsonComponent.java @@ -0,0 +1,76 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.json.object; + +//tag::code[] +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.SerializerProvider; + +import org.springframework.boot.jackson.JsonComponent; +import org.springframework.boot.jackson.JsonObjectDeserializer; +import org.springframework.boot.jackson.JsonObjectSerializer; + +@JsonComponent +public class MyJsonComponent { + + public static class Serializer extends JsonObjectSerializer { + + @Override + protected void serializeObject(MyObject value, JsonGenerator jgen, SerializerProvider provider) + throws IOException { + jgen.writeStringField("name", value.getName()); + jgen.writeNumberField("age", value.getAge()); + } + + } + + public static class Deserializer extends JsonObjectDeserializer { + + @Override + protected MyObject deserializeObject(JsonParser jsonParser, DeserializationContext context, ObjectCodec codec, + JsonNode tree) throws IOException { + String name = nullSafeValue(tree.get("name"), String.class); + int age = nullSafeValue(tree.get("age"), Integer.class); + return new MyObject(name, age); + } + + } + +} +// end::code[] + +class MyObject { + + MyObject(String name, int age) { + } + + String getName() { + return null; + } + + Integer getAge() { + return null; + + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/package-info.java new file mode 100644 index 000000000000..ed5dd710ce0c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Developing Web Applications" section. + */ +package org.springframework.boot.docs.springbootfeatures.webapplications; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/CorsConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/CorsConfiguration.java new file mode 100644 index 000000000000..6b253b255ef0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/CorsConfiguration.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration(proxyBeanMethods = false) +public class CorsConfiguration { + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/api/**"); + } + + }; + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ErrorPageConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ErrorPageConfiguration.java new file mode 100644 index 000000000000..6792a8fb86b6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ErrorPageConfiguration.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; + +@Configuration +public class ErrorPageConfiguration { + + @Bean + public ErrorPageRegistrar errorPageRegistrar() { + return this::registerErrorPages; + } + + private void registerErrorPages(ErrorPageRegistry registry) { + registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyControllerAdvice.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyControllerAdvice.java new file mode 100644 index 000000000000..02e3ce2c7055 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyControllerAdvice.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletRequest; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +@ControllerAdvice(basePackageClasses = AcmeController.class) +public class MyControllerAdvice extends ResponseEntityExceptionHandler { + + @ResponseBody + @ExceptionHandler(MyException.class) + ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { + HttpStatus status = getStatus(request); + return new ResponseEntity<>(new MyErrorBody(status.value(), ex.getMessage()), status); + } + + private HttpStatus getStatus(HttpServletRequest request) { + Integer code = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + HttpStatus status = HttpStatus.resolve(code); + return (status != null) ? status : HttpStatus.INTERNAL_SERVER_ERROR; + } + +} +// end::code[] + +class AcmeController { + +} + +class MyException extends RuntimeException { + +} + +class MyErrorBody { + + MyErrorBody(int value, String message) { + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyErrorViewResolver.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyErrorViewResolver.java new file mode 100644 index 000000000000..cfe32cf3b273 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyErrorViewResolver.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; +import org.springframework.http.HttpStatus; +import org.springframework.web.servlet.ModelAndView; + +public class MyErrorViewResolver implements ErrorViewResolver { + + @Override + public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map model) { + // Use the request or status to optionally return a ModelAndView + if (status == HttpStatus.INSUFFICIENT_STORAGE) { + // We could add custom model values here + new ModelAndView("myview"); + } + return null; + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyRestController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyRestController.java new file mode 100644 index 000000000000..5983f3a69f02 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/MyRestController.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/users") +public class MyRestController { + + private final UserRepository userRepository; + + private final CustomerRepository customerRepository; + + public MyRestController(UserRepository userRepository, CustomerRepository customerRepository) { + this.userRepository = userRepository; + this.customerRepository = customerRepository; + } + + @GetMapping("/{user}") + public User getUser(@PathVariable Long userId) { + return this.userRepository.findById(userId).get(); + } + + @GetMapping("/{user}/customers") + List getUserCustomers(@PathVariable Long userId) { + return this.userRepository.findById(userId).map(this.customerRepository::findByUser).get(); + } + + @DeleteMapping("/{user}") + public void deleteUser(@PathVariable Long userId) { + this.userRepository.deleteById(userId); + } + +} +// end::code[] + +interface UserRepository extends CrudRepository { + +} + +interface CustomerRepository extends CrudRepository { + + List findByUser(User user); + +} + +class User { + + List getCustomers() { + return null; + } + +} + +class Customer { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ServletFilterConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ServletFilterConfiguration.java new file mode 100644 index 000000000000..9038e56af58e --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/servlet/ServletFilterConfiguration.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.servlet; + +//tag::code[] +import java.io.IOException; +import java.util.EnumSet; + +import javax.servlet.DispatcherType; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.GenericFilterBean; + +@Configuration +public class ServletFilterConfiguration { + + @Bean + public FilterRegistrationBean myFilter() { + FilterRegistrationBean registration = new FilterRegistrationBean<>(new MyFilter()); + // ... + registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class)); + return registration; + } + +} +// end::code[] + +class MyFilter extends GenericFilterBean { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CodecConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CodecConfiguration.java new file mode 100644 index 000000000000..01e2af66172c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CodecConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.webflux; + +//tag::code[] +import org.springframework.boot.web.codec.CodecCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.codec.ServerSentEventHttpMessageReader; + +@Configuration(proxyBeanMethods = false) +public class CodecConfiguration { + + @Bean + public CodecCustomizer myCodecCustomizer() { + return (configurer) -> { + configurer.registerDefaults(false); + configurer.customCodecs().register(new ServerSentEventHttpMessageReader()); + // ... + }; + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CustomErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CustomErrorWebExceptionHandler.java new file mode 100644 index 000000000000..525b79acb2cf --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/CustomErrorWebExceptionHandler.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.webflux; + +//tag::code[] +import reactor.core.publisher.Mono; + +import org.springframework.boot.autoconfigure.web.WebProperties.Resources; +import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; +import org.springframework.boot.web.reactive.error.ErrorAttributes; +import org.springframework.context.ApplicationContext; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder; + +@Component +public class CustomErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { + + public CustomErrorWebExceptionHandler(ErrorAttributes errorAttributes, Resources resources, + ApplicationContext applicationContext) { + super(errorAttributes, resources, applicationContext); + } + + @Override + protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { + return RouterFunctions.route(this::acceptsXml, this::handleErrorAsXml); + } + + private boolean acceptsXml(ServerRequest request) { + return request.headers().accept().contains(MediaType.APPLICATION_XML); + } + + public Mono handleErrorAsXml(ServerRequest request) { + BodyBuilder builder = ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR); + // ... additional builder calls + return builder.build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/MyRestController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/MyRestController.java new file mode 100644 index 000000000000..d4b6d528ebfd --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/MyRestController.java @@ -0,0 +1,83 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.webflux; + +//tag::code[] +import java.util.List; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import org.springframework.data.repository.reactive.ReactiveCrudRepository; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/users") +public class MyRestController { + + private final UserRepository userRepository; + + private final CustomerRepository customerRepository; + + public MyRestController(UserRepository userRepository, CustomerRepository customerRepository) { + this.userRepository = userRepository; + this.customerRepository = customerRepository; + } + + @GetMapping("/{user}") + public Mono getUser(@PathVariable Long userId) { + return this.userRepository.findById(userId); + } + + @GetMapping("/{user}/customers") + Flux getUserCustomers(@PathVariable Long userId) { + return this.userRepository.findById(userId).flatMapMany(this.customerRepository::findByUser); + } + + @DeleteMapping("/{user}") + public void deleteUser(@PathVariable Long userId) { + this.userRepository.deleteById(userId); + } + +} +// end::code[] + +interface UserRepository extends ReactiveCrudRepository { + +} + +interface CustomerRepository extends ReactiveCrudRepository { + + Flux findByUser(User user); + +} + +class User { + + List getCustomers() { + return null; + } + +} + +class Customer { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/RoutingConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/RoutingConfiguration.java new file mode 100644 index 000000000000..089ee7ac3758 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/RoutingConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.webflux.fn; + +//tag::code[] +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.server.RequestPredicate; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.ServerResponse; + +import static org.springframework.web.reactive.function.server.RequestPredicates.DELETE; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + +@Configuration(proxyBeanMethods = false) +public class RoutingConfiguration { + + private static final RequestPredicate ACCEPT_JSON = accept(MediaType.APPLICATION_JSON); + + @Bean + public RouterFunction monoRouterFunction(UserHandler userHandler) { + // @formatter:off + return route( + GET("/{user}").and(ACCEPT_JSON), userHandler::getUser).andRoute( + GET("/{user}/customers").and(ACCEPT_JSON), userHandler::getUserCustomers).andRoute( + DELETE("/{user}").and(ACCEPT_JSON), userHandler::deleteUser); + // @formatter:on + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/UserHandler.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/UserHandler.java new file mode 100644 index 000000000000..8ddd5ef6a7ef --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/webflux/fn/UserHandler.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.webapplications.webflux.fn; + +//tag::code[] +import reactor.core.publisher.Mono; + +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; + +@Component +public class UserHandler { + + public Mono getUser(ServerRequest request) { + // ... + return ServerResponse.ok().build(); + } + + public Mono getUserCustomers(ServerRequest request) { + // ... + return ServerResponse.ok().build(); + } + + public Mono deleteUser(ServerRequest request) { + // ... + return ServerResponse.ok().build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webclient/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webclient/package-info.java new file mode 100644 index 000000000000..991a5d5aaa42 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webclient/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - Calling REST Services with WebClient" section. + */ +package org.springframework.boot.docs.springbootfeatures.webclient; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/websockets/package-info.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/websockets/package-info.java new file mode 100644 index 000000000000..71cf783a86ef --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/websockets/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Examples for the "Spring Boot Features - WebSockets" section. + */ +package org.springframework.boot.docs.springbootfeatures.websockets; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateProxyCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateProxyCustomizationExample.java deleted file mode 100644 index ae9a13c66f59..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/client/RestTemplateProxyCustomizationExample.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.web.client; - -import org.apache.http.HttpException; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.DefaultProxyRoutePlanner; -import org.apache.http.protocol.HttpContext; - -import org.springframework.boot.web.client.RestTemplateCustomizer; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; - -/** - * Example configuration for using a {@link RestTemplateCustomizer} to configure a proxy. - * - * @author Andy Wilkinson - */ -public class RestTemplateProxyCustomizationExample { - - /** - * A {@link RestTemplateCustomizer} that applies an HttpComponents-based request - * factory that is configured to use a proxy. - */ - // tag::customizer[] - static class ProxyCustomizer implements RestTemplateCustomizer { - - @Override - public void customize(RestTemplate restTemplate) { - HttpHost proxy = new HttpHost("proxy.example.com"); - HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy) { - - @Override - public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) - throws HttpException { - if (target.getHostName().equals("192.168.0.5")) { - return null; - } - return super.determineProxy(target, request, context); - } - - }).build(); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); - } - - } - // end::customizer[] - -} diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java similarity index 84% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java index 0a55c60775a4..f03001cec30f 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/actuate/metrics/MetricsHealthMicrometerExportExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.actuate.metrics; +package org.springframework.boot.docs.howto.actuator; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; @@ -36,12 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link MetricsHealthMicrometerExportExample}. + * Tests for {@link MetricsHealthMicrometerExport}. * * @author Phillip Webb */ @SpringBootTest -class MetricsHealthMicrometerExportExampleTests { +class MetricsHealthMicrometerExportTests { @Autowired private MeterRegistry registry; @@ -53,14 +53,14 @@ void registryExportsHealth() throws Exception { } @Configuration(proxyBeanMethods = false) - @Import(MetricsHealthMicrometerExportExample.HealthMetricsConfiguration.class) + @Import(MetricsHealthMicrometerExport.HealthMetricsConfiguration.class) @ImportAutoConfiguration(classes = { HealthContributorAutoConfiguration.class, MetricsAutoConfiguration.class, HealthEndpointAutoConfiguration.class }) static class Config { @Bean - MetricsHealthMicrometerExportExample example() { - return new MetricsHealthMicrometerExportExample(); + MetricsHealthMicrometerExport example() { + return new MetricsHealthMicrometerExport(); } @Bean diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/BasicDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java similarity index 86% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/BasicDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java index 2d441f5c4069..a4b017ffca87 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/BasicDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import java.sql.SQLException; @@ -32,14 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link BasicDataSourceExample}. + * Test for {@link BasicDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = "app.datasource.jdbcUrl=jdbc:h2:mem:basic;DB_CLOSE_DELAY=-1") -@Import(BasicDataSourceExample.BasicDataSourceConfiguration.class) -class BasicDataSourceExampleTests { +@Import(BasicDataSourceConfiguration.class) +class BasicDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java similarity index 86% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java index 10a801536b2b..4a549830abe7 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/CompleteTwoDataSourcesExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import java.sql.SQLException; @@ -32,14 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link CompleteTwoDataSourcesExample}. + * Tests for {@link CompleteDataSourcesConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest -@Import(CompleteTwoDataSourcesExample.CompleteDataSourcesConfiguration.class) -class CompleteTwoDataSourcesExampleTests { +@Import(CompleteDataSourcesConfiguration.class) +class CompleteDataSourcesConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java similarity index 86% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java index 0e290c19f434..792a2ad853e8 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/ConfigurableDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import java.sql.SQLException; @@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link SimpleDataSourceExample}. + * Test for {@link ConfigurableDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1", "app.datasource.configuration.maximum-pool-size=42" }) -@Import(ConfigurableDataSourceExample.ConfigurableDataSourceConfiguration.class) -class ConfigurableDataSourceExampleTests { +@Import(ConfigurableDataSourceConfiguration.class) +class ConfigurableDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SampleApp.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SampleApp.java similarity index 90% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SampleApp.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SampleApp.java index 442293507327..230ccc2ad7cb 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SampleApp.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SampleApp.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import javax.sql.DataSource; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java similarity index 87% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java index f64d9b876560..35a387c09767 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import java.sql.SQLException; @@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link SimpleDataSourceExample}. + * Test for {@link SimpleDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1", "app.datasource.maximum-pool-size=42" }) -@Import(SimpleDataSourceExample.SimpleDataSourceConfiguration.class) -class SimpleDataSourceExampleTests { +@Import(SimpleDataSourceConfiguration.class) +class SimpleDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java index 1866436a3915..c44689301928 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/jdbc/SimpleTwoDataSourcesExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.jdbc; +package org.springframework.boot.docs.howto.dataaccess; import java.sql.SQLException; @@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link SimpleTwoDataSourcesExample}. + * Tests for {@link SimpleDataSourcesConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1", "app.datasource.second.max-total=42" }) -@Import(SimpleTwoDataSourcesExample.SimpleDataSourcesConfiguration.class) -class SimpleTwoDataSourcesExampleTests { +@Import(SimpleDataSourcesConfiguration.class) +class SimpleDataSourcesConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java index 5fd9dd02e3c3..db2bb9163321 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.howto.embeddedwebservers; import org.apache.catalina.Context; import org.apache.tomcat.util.http.LegacyCookieProcessor; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; -import org.springframework.boot.docs.context.embedded.TomcatLegacyCookieProcessorExample.LegacyCookieProcessorConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor; @@ -32,11 +31,11 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link TomcatLegacyCookieProcessorExample}. + * Tests for {@link LegacyCookieProcessorConfiguration}. * * @author Andy Wilkinson */ -class TomcatLegacyCookieProcessorExampleTests { +class LegacyCookieProcessorConfigurationTests { @Test void cookieProcessorIsCustomized() { diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessorTests.java similarity index 78% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessorTests.java index 2dc4ff7f6f7c..d43d86b81d19 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/EnvironmentPostProcessorExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/MyEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.context; +package org.springframework.boot.docs.howto.springbootapplication; import org.junit.jupiter.api.Test; @@ -24,18 +24,18 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link EnvironmentPostProcessorExample}. + * Tests for {@link MyEnvironmentPostProcessor}. * * @author Stephane Nicoll */ -class EnvironmentPostProcessorExampleTests { +class MyEnvironmentPostProcessorTests { private final StandardEnvironment environment = new StandardEnvironment(); @Test void applyEnvironmentPostProcessor() { assertThat(this.environment.containsProperty("test.foo.bar")).isFalse(); - new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment, new SpringApplication()); + new MyEnvironmentPostProcessor().postProcessEnvironment(this.environment, new SpringApplication()); assertThat(this.environment.containsProperty("test.foo.bar")).isTrue(); assertThat(this.environment.getProperty("test.foo.bar")).isEqualTo("value"); } diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemPropertiesTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemPropertiesTests.java similarity index 94% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemPropertiesTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemPropertiesTests.java index f9155f5a0cca..f2f76bee65e5 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/javabean/AppSystemPropertiesTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.javabean; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.constructorbinding; import java.util.function.Consumer; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemPropertiesTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemPropertiesTests.java similarity index 94% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemPropertiesTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemPropertiesTests.java index f64e49589684..0d12e58e778d 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/properties/bind/constructor/AppSystemPropertiesTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.properties.bind.constructor; +package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.javabeanbinding; import java.util.function.Consumer; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExampleTests.java similarity index 91% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExampleTests.java index 3da2ba10d3e7..457b994fbaff 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/builder/SpringApplicationBuilderExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExampleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.builder; +package org.springframework.boot.docs.springbootfeatures.springapplication; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTestsTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTestsTests.java new file mode 100644 index 000000000000..e7b6389a6e71 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTestsTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.testing; + +/** + * Tests for {@link OutputCaptureTests}. + * + * @author Stephane Nicoll + */ +class OutputCaptureTestsTests extends OutputCaptureTests { + +} diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTestsTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTestsTests.java new file mode 100644 index 000000000000..7f00013f3d28 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTestsTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.testing; + +/** + * Tests for {@link UserServiceAutoConfigurationTests}. + * + * @author Stephane Nicoll + */ +class UserServiceAutoConfigurationTestsTests extends UserServiceAutoConfigurationTests { + +} diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTestsTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTestsTests.java new file mode 100644 index 000000000000..9729e9cff869 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTestsTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.testing.jmx; + +/** + * Tests for SampleJmxTests + * + * @author Stephane Nicoll + */ +class SampleJmxTestsTests extends SampleJmxTests { + +} diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTestsTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTestsTests.java new file mode 100644 index 000000000000..323dddb0b371 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTestsTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.springbootfeatures.testing.webclient; + +/** + * Tests for {@link SampleWebClientTests}. + * + * @author Stephane Nicoll + */ +class SampleWebClientTestsTests extends SampleWebClientTests { + +} diff --git a/spring-boot-project/spring-boot-properties-migrator/build.gradle b/spring-boot-project/spring-boot-properties-migrator/build.gradle index a1362beadc79..cd9da1f879ac 100644 --- a/spring-boot-project/spring-boot-properties-migrator/build.gradle +++ b/spring-boot-project/spring-boot-properties-migrator/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.assertj:assertj-core") testImplementation("org.springframework:spring-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle index b9540733436a..c9114745bf35 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle @@ -85,8 +85,6 @@ dependencies { testImplementation("org.testcontainers:neo4j") testImplementation("org.testcontainers:testcontainers") testImplementation("org.thymeleaf:thymeleaf") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } configurations { diff --git a/spring-boot-project/spring-boot-test/build.gradle b/spring-boot-project/spring-boot-test/build.gradle index 7a1c2913d995..2096486a845c 100644 --- a/spring-boot-project/spring-boot-test/build.gradle +++ b/spring-boot-project/spring-boot-test/build.gradle @@ -49,7 +49,6 @@ dependencies { testImplementation("org.springframework:spring-webmvc") testImplementation("org.testng:testng") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.junit.vintage:junit-vintage-engine") } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java index 435e22a46a94..18ba59787bce 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; +import org.springframework.http.RequestEntity.UriTemplateRequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; @@ -965,7 +966,7 @@ public TestRestTemplate withBasicAuth(String username, String password) { @SuppressWarnings({ "rawtypes", "unchecked" }) private RequestEntity createRequestEntityWithRootAppliedUri(RequestEntity requestEntity) { return new RequestEntity(requestEntity.getBody(), requestEntity.getHeaders(), requestEntity.getMethod(), - applyRootUriIfNecessary(requestEntity.getUrl()), requestEntity.getType()); + applyRootUriIfNecessary(resolveUri(requestEntity)), requestEntity.getType()); } private URI applyRootUriIfNecessary(URI uri) { @@ -976,6 +977,23 @@ private URI applyRootUriIfNecessary(URI uri) { return uri; } + private URI resolveUri(RequestEntity entity) { + if (entity instanceof UriTemplateRequestEntity) { + UriTemplateRequestEntity templatedUriEntity = (UriTemplateRequestEntity) entity; + if (templatedUriEntity.getVars() != null) { + return this.restTemplate.getUriTemplateHandler().expand(templatedUriEntity.getUriTemplate(), + templatedUriEntity.getVars()); + } + else if (templatedUriEntity.getVarsMap() != null) { + return this.restTemplate.getUriTemplateHandler().expand(templatedUriEntity.getUriTemplate(), + templatedUriEntity.getVarsMap()); + } + throw new IllegalStateException( + "No variables specified for URI template: " + templatedUriEntity.getUriTemplate()); + } + return entity.getUrl(); + } + /** * Options used to customize the Apache HTTP Client. */ diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java index 341e9fef59ba..fe945952548e 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -233,6 +233,36 @@ void withBasicAuthShouldUseNoOpErrorHandler() throws Exception { Class.forName("org.springframework.boot.test.web.client.TestRestTemplate$NoOpResponseErrorHandler")); } + @Test + void exchangeWithRelativeTemplatedUrlRequestEntity() throws Exception { + RequestEntity entity = RequestEntity.get("/a/b/c.{ext}", "txt").build(); + TestRestTemplate template = new TestRestTemplate(); + ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class); + MockClientHttpRequest request = new MockClientHttpRequest(); + request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK)); + URI absoluteUri = URI.create("http://localhost:8080/a/b/c.txt"); + given(requestFactory.createRequest(eq(absoluteUri), eq(HttpMethod.GET))).willReturn(request); + template.getRestTemplate().setRequestFactory(requestFactory); + LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment()); + template.setUriTemplateHandler(uriTemplateHandler); + template.exchange(entity, String.class); + verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); + } + + @Test + void exchangeWithAbsoluteTemplatedUrlRequestEntity() throws Exception { + RequestEntity entity = RequestEntity.get("https://api.example.com/a/b/c.{ext}", "txt").build(); + TestRestTemplate template = new TestRestTemplate(); + ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class); + MockClientHttpRequest request = new MockClientHttpRequest(); + request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK)); + URI absoluteUri = URI.create("https://api.example.com/a/b/c.txt"); + given(requestFactory.createRequest(eq(absoluteUri), eq(HttpMethod.GET))).willReturn(request); + template.getRestTemplate().setRequestFactory(requestFactory); + template.exchange(entity, String.class); + verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); + } + @Test void deleteHandlesRelativeUris() throws IOException { verifyRelativeUriHandling(TestRestTemplate::delete); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle index 3135d39d6bdc..5d0e114fc81b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle @@ -24,8 +24,6 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools")) implementation("org.springframework:spring-core") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task copyIntegrationTestSources(type: Copy) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/build.gradle index 8f0517ceac99..c131957b7459 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/build.gradle @@ -13,6 +13,4 @@ dependencies { testImplementation("org.assertj:assertj-core") testImplementation("org.springframework:spring-core") testImplementation("org.junit.jupiter:junit-jupiter") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/build.gradle index 2d6b063b7c8f..56a9bc77170e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/build.gradle @@ -13,7 +13,7 @@ dependencies { api("org.apache.commons:commons-compress:1.19") api("org.apache.httpcomponents:httpclient") api("org.springframework:spring-core") - + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) testImplementation("com.jayway.jsonpath:json-path") testImplementation("org.assertj:assertj-core") @@ -23,6 +23,4 @@ dependencies { testImplementation("org.mockito:mockito-core") testImplementation("org.mockito:mockito-junit-jupiter") testImplementation("org.skyscreamer:jsonassert") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle index 7e0a5160b6ef..1ceb415f3b0f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.assertj:assertj-core") testImplementation("org.springframework:spring-core") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/build.gradle index b23888d2248a..bcd85c1ecea4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/build.gradle @@ -26,6 +26,4 @@ dependencies { testImplementation("org.mockito:mockito-core") testImplementation("org.projectlombok:lombok") testImplementation("org.springframework:spring-core") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle index a3544fa203dd..0153b836477f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle @@ -43,8 +43,6 @@ dependencies { testImplementation("org.mockito:mockito-core") testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:testcontainers") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } gradlePlugin { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibility.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibility.java index 73fe2698f06b..9617f0d94de6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibility.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibility.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,4 +48,6 @@ */ boolean configurationCache() default false; + String versionsLessThan() default ""; + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java index 52238d14ab31..025b42690563 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java @@ -32,6 +32,7 @@ import org.springframework.boot.gradle.testkit.GradleBuild; import org.springframework.boot.gradle.testkit.GradleBuildExtension; +import org.springframework.util.StringUtils; /** * {@link Extension} that runs {@link TestTemplate templated tests} against multiple @@ -48,24 +49,33 @@ final class GradleCompatibilityExtension implements TestTemplateInvocationContex JavaVersion javaVersion = JavaVersion.current(); if (javaVersion.isCompatibleWith(JavaVersion.VERSION_14) || javaVersion.isCompatibleWith(JavaVersion.VERSION_13)) { - GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1", "current"); + GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1", "current", "7.0-milestone-1"); } else { - GRADLE_VERSIONS = Arrays.asList("5.6.4", "6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1", "current"); + GRADLE_VERSIONS = Arrays.asList("5.6.4", "6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1", "current", + "7.0-milestone-1"); } } @Override public Stream provideTestTemplateInvocationContexts(ExtensionContext context) { - return GRADLE_VERSIONS.stream().flatMap((version) -> { + Stream gradleVersions = GRADLE_VERSIONS.stream().map((version) -> { if (version.equals("current")) { - version = GradleVersion.current().getVersion(); + return GradleVersion.current().getVersion(); } + return version; + }); + GradleCompatibility gradleCompatibility = AnnotationUtils + .findAnnotation(context.getRequiredTestClass(), GradleCompatibility.class).get(); + if (StringUtils.hasText(gradleCompatibility.versionsLessThan())) { + GradleVersion upperExclusive = GradleVersion.version(gradleCompatibility.versionsLessThan()); + gradleVersions = gradleVersions + .filter((version) -> GradleVersion.version(version).compareTo(upperExclusive) < 0); + } + return gradleVersions.flatMap((version) -> { List invocationContexts = new ArrayList<>(); invocationContexts.add(new GradleVersionTestTemplateInvocationContext(version, false)); - boolean configurationCache = AnnotationUtils - .findAnnotation(context.getRequiredTestClass(), GradleCompatibility.class).get() - .configurationCache(); + boolean configurationCache = gradleCompatibility.configurationCache(); if (configurationCache && GradleVersion.version(version).compareTo(GradleVersion.version("6.7")) >= 0) { invocationContexts.add(new GradleVersionTestTemplateInvocationContext(version, true)); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/MavenPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/MavenPluginActionIntegrationTests.java index b6a55b8a91d4..1575799b5a61 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/MavenPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/MavenPluginActionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ * * @author Andy Wilkinson */ -@GradleCompatibility +@GradleCompatibility(versionsLessThan = "7.0-milestone-1") class MavenPluginActionIntegrationTests { GradleBuild gradleBuild; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests.java index 46a9f07b49fc..7f5c9a0dccb1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ * * @author Andy Wilkinson */ -@GradleCompatibility +@GradleCompatibility(versionsLessThan = "7.0-milestone-1") class MavenIntegrationTests { GradleBuild gradleBuild; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/build.gradle index 24dbd39f3322..bd774a035efa 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.mockito:mockito-core") testImplementation("org.mockito:mockito-junit-jupiter") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle index 50bb253f3591..8ed6b82eeaf7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle @@ -31,8 +31,6 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.mockito:mockito-core") testImplementation("org.zeroturnaround:zt-zip:1.13") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } sourceSets { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-loader/build.gradle index 62d85cc26d4e..fa85d4849ca1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/build.gradle @@ -18,7 +18,6 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") testRuntimeOnly("org.bouncycastle:bcprov-jdk16:1.46") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.slf4j:jcl-over-slf4j") testRuntimeOnly("org.springframework:spring-webmvc") -} +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle index 543fdec75138..3336e60becf4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle @@ -42,8 +42,6 @@ dependencies { testImplementation("org.mockito:mockito-core") testImplementation("org.mockito:mockito-junit-jupiter") testImplementation("org.springframework:spring-core") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task syncSpringBootDependenciesBom(type: Sync) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle index 7550fca69fcc..e0df8cd77d11 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle @@ -34,5 +34,4 @@ dependencies { testImplementation("org.springframework:spring-context") testRuntimeOnly("org.hibernate.validator:hibernate-validator") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index 17a21e800655..9a644b6823d4 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -99,7 +99,6 @@ dependencies { testImplementation("org.springframework.data:spring-data-r2dbc") testImplementation("org.xerial:sqlite-jdbc") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.testcontainers:jdbc") { exclude group: "javax.annotation", module: "javax.annotation-api" exclude group: "javax.xml.bind", module: "jaxb-api" diff --git a/spring-boot-tests/spring-boot-deployment-tests/build.gradle b/spring-boot-tests/spring-boot-deployment-tests/build.gradle index 390b2fdecfd0..738f63fcd1e5 100644 --- a/spring-boot-tests/spring-boot-deployment-tests/build.gradle +++ b/spring-boot-tests/spring-boot-deployment-tests/build.gradle @@ -27,8 +27,6 @@ dependencies { intTestImplementation("org.springframework:spring-web") providedRuntime(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } intTest { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-configuration-processor-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-configuration-processor-tests/build.gradle index e65a068f98de..d5345ed8988f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-configuration-processor-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-configuration-processor-tests/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-configuration-metadata")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle index 7d5b48f639b9..f0b5d3fb9b68 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle @@ -20,8 +20,6 @@ dependencies { intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) intTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) intTestImplementation("org.testcontainers:testcontainers") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task syncMavenRepository(type: Sync) { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle index 7dca5512502e..7a39e57c4673 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle @@ -20,8 +20,6 @@ dependencies { intTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) intTestImplementation("org.testcontainers:junit-jupiter") intTestImplementation("org.testcontainers:testcontainers") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task syncMavenRepository(type: Sync) { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle index 437a09e1d624..51210a793853 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle @@ -34,7 +34,6 @@ dependencies { testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-undertow", configuration: "mavenRepository")) testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-logging")) - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task prepareMavenBinaries(type: org.springframework.boot.build.mavenplugin.PrepareMavenBinaries) { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/build.gradle index 1c6317df0fd2..aeb28b9cf374 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-activemq")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/build.gradle index f3eca092fab2..1d627427fcd6 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/build.gradle @@ -16,5 +16,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testRuntimeOnly("org.apache.httpcomponents:httpclient") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/build.gradle index 229268cc07ed..7b9701752062 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/build.gradle @@ -17,6 +17,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/build.gradle index 1f5f780b9eeb..4f215d7a02db 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/build.gradle @@ -11,6 +11,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/build.gradle index a8ef96871308..5f1fa1b6221d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/build.gradle @@ -12,6 +12,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle index 2b8e634f4574..2e151b5fd01a 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle @@ -15,7 +15,5 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - testRuntimeOnly("org.apache.httpcomponents:httpclient") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/build.gradle index d4d3bf953f22..691266ec9d27 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/build.gradle @@ -7,6 +7,4 @@ description = "Spring Boot AMQP smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-amqp")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/build.gradle index cde9b42f1394..2b029afd2221 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/build.gradle @@ -7,6 +7,4 @@ description = "Spring Boot animated banner smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle index 0603061ba460..3efb8cdc8acf 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle @@ -37,8 +37,6 @@ dependencies { testImplementation("org.assertj:assertj-core") testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.springframework:spring-core") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } task syncTestRepository(type: Sync) { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-aop/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-aop/build.gradle index de33ac75017a..92fc71db7a02 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-aop/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-aop/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-aop")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/build.gradle index b36a31f15994..d8f00c7c2517 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies"))) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.springframework:spring-websocket") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/build.gradle index d88dcf683560..8ad05121aa92 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/build.gradle @@ -7,10 +7,8 @@ description = "Spring Boot Batch smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-batch")) - + runtimeOnly("org.hsqldb:hsqldb") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle index b5fdd75e5cf1..84e14c23b1fc 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle @@ -39,8 +39,6 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - if (project.hasProperty("cache")) { caches[project.getProperty("cache")].each { runtimeOnly it } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/build.gradle index 9700b96651fc..9f4ceffe3cf0 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/build.gradle index 4b39e977d132..20b46dc9149a 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-elasticsearch")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/build.gradle index 73795b04f974..577447eabf24 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/build.gradle @@ -12,6 +12,4 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/build.gradle index 6c11ffa51cc0..d009a1eeb626 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/build.gradle @@ -13,6 +13,4 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/build.gradle index acf2a51047d1..0c9f1ed18a78 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/build.gradle @@ -11,6 +11,4 @@ dependencies { runtimeOnly("com.unboundid:unboundid-ldapsdk") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/build.gradle index 59ccf3343433..1c429284208a 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/build.gradle @@ -11,6 +11,4 @@ dependencies { runtimeOnly("de.flapdoodle.embed:de.flapdoodle.embed.mongo") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/build.gradle index bfd3e16ce865..233d3efeab12 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-neo4j")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-flyway/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-flyway/build.gradle index 64f8c9576010..3f4a53ce7c78 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-flyway/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-flyway/build.gradle @@ -18,6 +18,4 @@ dependencies { testImplementation("io.projectreactor:reactor-test") testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:postgresql") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-liquibase/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-liquibase/build.gradle index a948d4dc3f06..f07ff09b97e0 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-liquibase/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc-liquibase/build.gradle @@ -18,6 +18,4 @@ dependencies { testImplementation("io.projectreactor:reactor-test") testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:postgresql") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle index aba0ce257263..c18db766961b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle @@ -13,6 +13,4 @@ dependencies { runtimeOnly("io.r2dbc:r2dbc-h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/build.gradle index 5524f19aa6ec..2d304c6c05b0 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/build.gradle index d228f85d939e..b0e2be031049 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/build.gradle @@ -17,5 +17,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testRuntimeOnly("com.jayway.jsonpath:json-path") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/build.gradle index 197e81a4c187..e27a3d9b4c2c 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/build.gradle @@ -17,6 +17,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/build.gradle index 2d67291bb56e..b04bc8a21dfb 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/build.gradle @@ -14,6 +14,4 @@ dependencies { runtimeOnly("org.flywaydb:flyway-core") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/build.gradle index dc0900f09e58..e1f47ebeabc7 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-hateoas")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle index ffb9c2caca01..c64d5334d12a 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle @@ -21,6 +21,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-webflux")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/build.gradle index fff415813e7a..27369d6dc409 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/build.gradle @@ -19,6 +19,4 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/build.gradle index 75f709e9c3ff..a0506b33203a 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/build.gradle @@ -13,6 +13,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.awaitility:awaitility") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/build.gradle index 17e90667fb96..f93f3fa6d5cc 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/build.gradle @@ -15,6 +15,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/build.gradle index 0ab1d2b0f8b9..5e16488338c6 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/build.gradle @@ -27,6 +27,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/build.gradle index cef000460df1..b39afaf3ed44 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/build.gradle @@ -14,6 +14,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testRuntimeOnly("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/build.gradle index b7272f158d48..b204e4a35e31 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/build.gradle @@ -12,6 +12,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle index 78717d0e64e5..f571bc0c59c8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle @@ -22,6 +22,4 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/build.gradle index 768a8884d2c6..3af4cc0d3b8f 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/build.gradle @@ -20,6 +20,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle index ae9626fae32c..d44518a14d43 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle @@ -11,8 +11,6 @@ dependencies { testImplementation("org.junit.vintage:junit-vintage-engine") { exclude group: "org.hamcrest", module: "hamcrest-core" } - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } test { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/build.gradle index 7906ed30eb0a..33a82ff144bd 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.awaitility:awaitility") testImplementation("org.springframework.kafka:spring-kafka-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/build.gradle index 2a44c5ad16ac..60ab8957b507 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/build.gradle @@ -14,6 +14,4 @@ dependencies { runtimeOnly("com.h2database:h2") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-logback/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-logback/build.gradle index 698eb510e78b..d7fced445fe5 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-logback/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-logback/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/build.gradle index 8156b9371fe1..9667845a0c97 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/build.gradle @@ -11,6 +11,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/build.gradle index 56ea47c5459f..aa4c52038605 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/build.gradle @@ -11,6 +11,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("com.squareup.okhttp3:mockwebserver:3.9.0") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/build.gradle index 4df9cda681d9..1f174d0bc2b8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.awaitility:awaitility") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-profile/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-profile/build.gradle index bbffd501f38f..e85bae25e21b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-profile/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-profile/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/build.gradle index f587ef59129b..dd6a52edf931 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/build.gradle @@ -11,6 +11,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/build.gradle index a72c5db2b2fb..f1d8cb6bd078 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/build.gradle @@ -13,6 +13,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.awaitility:awaitility") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/build.gradle index 55bea7f7160a..890f42886877 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/build.gradle index bd0ed8c150f5..17d98b4895c2 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/build.gradle @@ -11,6 +11,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("com.squareup.okhttp3:mockwebserver:3.9.0") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-rsocket/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-rsocket/build.gradle index d13d8ed2682c..3194511e54cb 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-rsocket/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-rsocket/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("io.projectreactor:reactor-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/build.gradle index a3eef619ea6f..2a707f22f509 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/build.gradle @@ -11,6 +11,4 @@ dependencies { implementation("org.springframework.security:spring-security-saml2-service-provider") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-jersey/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-jersey/build.gradle index ea90b135c687..f896b2b24685 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-jersey/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-jersey/build.gradle @@ -12,6 +12,4 @@ dependencies { implementation("org.jolokia:jolokia-core") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/build.gradle index affb797e5cb5..08f52a225973 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("io.projectreactor:reactor-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure/build.gradle index 40e1ac12f156..13bc2d8953c4 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-secure/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-security")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/build.gradle index 74a5900f4697..ae5060934179 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/build.gradle @@ -13,5 +13,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat")) - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/build.gradle index 4cc5a8fbff7f..a90b4f9bc506 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/build.gradle @@ -24,6 +24,4 @@ dependencies { sessionStores[project.findProperty("sessionStore") ?: "mongodb"].each { runtimeOnly it } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle index eba7d8b5bd61..bd0ef38690d3 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle @@ -33,6 +33,4 @@ dependencies { sessionStores[project.findProperty("sessionStore") ?: "jdbc"].each { runtimeOnly it } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-simple/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-simple/build.gradle index a1dbf6d40732..d6690b607c48 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-simple/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-simple/build.gradle @@ -13,6 +13,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/build.gradle index ed7ec90ae529..40bd131be74d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/build.gradle @@ -15,6 +15,4 @@ dependencies { testImplementation("org.assertj:assertj-core") testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.springframework:spring-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/build.gradle index 3e0438120787..2d2b2b9a50eb 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/build.gradle @@ -17,6 +17,4 @@ dependencies { testImplementation("org.seleniumhq.selenium:selenium-api") testImplementation("org.seleniumhq.selenium:htmlunit-driver") testImplementation("net.sourceforge.htmlunit:htmlunit") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-testng/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-testng/build.gradle index be4cb7ca5222..14bc6715cdd1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-testng/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-testng/build.gradle @@ -14,8 +14,6 @@ dependencies { testImplementation("org.assertj:assertj-core") testImplementation("org.springframework:spring-test") testImplementation("org.testng:testng:6.8.13") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } test { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/build.gradle index ae3644aba473..edfd6c56f8b1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/build.gradle @@ -19,6 +19,4 @@ dependencies { providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/build.gradle index 4608f2d10728..a5d348812594 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/build.gradle @@ -10,6 +10,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/build.gradle index 32060d491c9e..cf32104bf8d9 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/build.gradle @@ -10,6 +10,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/build.gradle index 0bc12f506817..f5839181d10f 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/build.gradle @@ -11,6 +11,4 @@ dependencies { implementation("org.springframework:spring-webmvc") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/build.gradle index 0a80fcb36786..bc16f0a0b814 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/build.gradle @@ -20,6 +20,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/build.gradle index 7c206ffe52de..2cf550b516f9 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/build.gradle @@ -13,6 +13,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/build.gradle index 0bb5a3a4fa35..e125db178981 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/build.gradle @@ -12,6 +12,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-undertow")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-war/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-war/build.gradle index 1d80b78203ac..6aceb3d640bc 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-war/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-war/build.gradle @@ -19,6 +19,4 @@ dependencies { providedCompile("jakarta.servlet:jakarta.servlet-api") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/build.gradle index 9185a2f3b1e5..c734861fd5c1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/build.gradle @@ -10,6 +10,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/build.gradle index 65bdd8d81013..88e11842cb18 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/build.gradle @@ -13,6 +13,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/build.gradle index 5bf259d6d512..6c1baf158855 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/build.gradle @@ -19,6 +19,4 @@ dependencies { providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/build.gradle index af3ac3f1a375..c588cce09dd9 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/build.gradle @@ -12,6 +12,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/build.gradle index 1a212f595c7e..60950b2e735e 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/build.gradle @@ -10,6 +10,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/build.gradle index 9932c3a295df..38dd5599c8f4 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/build.gradle @@ -12,6 +12,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/build.gradle index 5151e2afc047..1f9c274153a1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/build.gradle @@ -15,6 +15,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/build.gradle index 55814d61dec4..8b3a7d1bbf95 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/build.gradle @@ -13,6 +13,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("org.apache.httpcomponents:httpclient") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/build.gradle index 753340b96ddf..67236bd4716d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/build.gradle @@ -20,6 +20,4 @@ dependencies { runtimeOnly("org.webjars:jquery:2.0.3-1") testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/build.gradle index 297dcd5dadff..388be0e26e43 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/build.gradle @@ -11,6 +11,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-validation")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/build.gradle index 381c3526441c..8d38e295b893 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/build.gradle @@ -27,6 +27,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("io.projectreactor:reactor-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/build.gradle index ec57092fc0b2..f0a6461ff720 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/build.gradle @@ -11,6 +11,4 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) testImplementation("io.projectreactor:reactor-test") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/build.gradle index a3adf617b9a1..8fd51c9c9dbf 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/build.gradle @@ -17,6 +17,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/build.gradle index 0622ae3e74ef..58e1f903b5c6 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/build.gradle @@ -12,6 +12,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/build.gradle index b973e4c1db0c..e15f1c653aa9 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-websocket")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/build.gradle index 9f4dbe00950f..9b3d85799f28 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/build.gradle @@ -12,6 +12,4 @@ dependencies { } testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-xml/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-xml/build.gradle index 8987b7753ab6..63103e966c72 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-xml/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-xml/build.gradle @@ -9,6 +9,4 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - - testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 694a83ca8ff3..79ab47a5552a 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -17,7 +17,7 @@ - +