From 9aad29da0c1ba19a261109ba3340447cd6796a98 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 2 May 2021 15:59:28 -0700 Subject: [PATCH] Extract code samples from docs See gh-6313 --- .../spring-boot-docs/build.gradle | 23 +++++- .../src/docs/asciidoc/actuator/endpoints.adoc | 71 +++--------------- .../src/docs/asciidoc/actuator/metrics.adoc | 72 ++++--------------- .../src/docs/asciidoc/attributes.adoc | 1 + .../other-build-systems.adoc | 12 +--- .../src/docs/asciidoc/cli/using-the-cli.adoc | 17 ++--- .../annotation-processor.adoc | 67 ++--------------- .../configuration-metadata/format.adoc | 23 +----- .../configuration-metadata/manual-hints.adoc | 9 +-- .../src/docs/asciidoc/deployment/cloud.adoc | 16 +---- .../getting-started/first-application.adoc | 21 +----- .../src/docs/asciidoc/howto/data-access.adoc | 51 ++++--------- .../src/docs/asciidoc/howto/jersey.adoc | 12 +--- .../src/docs/asciidoc/howto/messaging.adoc | 14 +--- .../howto/properties-and-configuration.adoc | 31 +++++--- .../src/docs/asciidoc/howto/security.adoc | 9 +-- .../src/docs/asciidoc/howto/spring-mvc.adoc | 20 ++---- .../docs/asciidoc/howto/testcontainers.adoc | 27 ++----- .../howto/testing-with-spring-security.adoc | 10 +-- .../howto/traditional-deployment.adoc | 68 +++--------------- .../src/docs/asciidoc/howto/webserver.adoc | 40 +++-------- .../asciidoc/using/auto-configuration.adoc | 9 +-- .../src/docs/asciidoc/using/devtools.adoc | 7 +- ...spring-beans-and-dependency-injection.adoc | 42 ++--------- .../asciidoc/using/structuring-your-code.adoc | 20 ++---- ...-the-springbootapplication-annotation.adoc | 36 ++-------- .../cli/usingthecli/run/WebApplication.groovy | 32 +++++++++ .../CustomDependencyManagement.groovy | 28 ++++++++ .../single/CustomDependencyManagement.groovy | 26 +++++++ .../MyReactiveHealthIndicator.java | 38 ++++++++++ .../MyHealthIndicator.java | 40 +++++++++++ .../MyInfoContributor.java | 33 +++++++++ .../exposeall/MySecurityConfiguration.java | 35 +++++++++ .../typical/MySecurityConfiguration.java | 36 ++++++++++ .../graphite/MyGraphiteConfiguration.java | 41 +++++++++++ .../export/jmx/MyJmxConfiguration.java | 41 +++++++++++ .../MyMeterRegistryConfiguration.java | 33 +++++++++ .../MyMeterRegistryConfiguration.java | 39 ++++++++++ .../timedannotation/all/Address.java | 21 ++++++ .../timedannotation/all/MyController.java | 40 +++++++++++ .../supported/timedannotation/all/Person.java | 21 ++++++ .../timedannotation/change/Address.java | 21 ++++++ .../timedannotation/change/MyController.java | 42 +++++++++++ .../timedannotation/change/Person.java | 21 ++++++ .../timedannotation/single/Address.java | 21 ++++++ .../timedannotation/single/MyController.java | 40 +++++++++++ .../timedannotation/single/Person.java | 21 ++++++ .../MyBuildTool.java | 49 +++++++++++++ .../MessagingProperties.java | 56 +++++++++++++++ .../ServerProperties.java | 65 +++++++++++++++++ .../nestedproperties/ServerProperties.java | 72 +++++++++++++++++++ .../format/group/AcmeProperties.java | 46 ++++++++++++ .../valuehint/SampleProperties.java | 38 ++++++++++ .../bindingtoservices/MyBean.java | 36 ++++++++++ .../restart/disable/MyApplication.java | 30 ++++++++ .../firstapplication/code/Example.java | 37 ++++++++++ .../FancyDataSource.java | 21 ++++++ .../FancyDataSourceConfiguration.java | 30 ++++++++ .../MyHibernateConfiguration.java} | 8 +-- .../standard/MyHibernateConfiguration.java | 32 +++++++++ .../Application.java | 30 ++++++++ .../City.java | 21 ++++++ ...stomEntityManagerFactoryConfiguration.java | 2 +- .../usemultipleentitymanagers/Customer.java | 21 ++++++ .../CustomerConfiguration.java | 26 +++++++ .../OrderConfiguration.java | 26 +++++++ .../Endpoint.java | 21 ++++++ .../JerseyConfig.java | 32 +++++++++ .../MyJmsConfiguration.java | 39 ++++++++++ .../application/MyApplication.java | 32 +++++++++ .../builder/MyApplication.java | 33 +++++++++ .../enablehttps/MySecurityConfig.java | 34 +++++++++ .../writejsonrestservice/MyController.java | 30 ++++++++ .../writejsonrestservice/MyThing.java | 21 ++++++ .../writexmlrestservice/MyThing.java | 36 ++++++++++ .../dynamicproperties/MyIntegrationTests.java | 45 ++++++++++++ .../vanilla/MyIntegrationTests.java | 38 ++++++++++ .../MySecurityTests.java | 40 +++++++++++ .../UserController.java | 21 ++++++ .../MyApplication.java | 41 +++++++++++ .../both/MyApplication.java | 40 +++++++++++ .../war/MyApplication.java | 36 ++++++++++ .../weblogic/MyApplication.java | 26 +++++++ .../springbean/disable/MyFilter.java | 23 ++++++ .../disable/MyFilterConfiguration.java | 33 +++++++++ .../MyTomcatWebServerCustomizer.java | 31 ++++++++ .../MyWebSocketConfiguration.java | 31 ++++++++ .../discoverport/MyWebIntegrationTests.java | 31 ++++++++ .../disablingspecific/MyApplication.java | 25 +++++++ .../multipleconstructors/AccountService.java | 21 ++++++ .../DatabaseAccountService.java | 46 ++++++++++++ .../multipleconstructors/RiskAssessor.java | 21 ++++++ .../singleconstructor/AccountService.java | 21 ++++++ .../DatabaseAccountService.java | 33 +++++++++ .../singleconstructor/RiskAssessor.java | 21 ++++++ .../locatingthemainclass/MyApplication.java | 29 ++++++++ .../MyAnotherConfig.java | 21 ++++++ .../individualannotations/MyApplication.java | 33 +++++++++ .../individualannotations/MyConfig.java | 21 ++++++ .../springapplication/MyApplication.java | 29 ++++++++ src/checkstyle/checkstyle-suppressions.xml | 2 +- 101 files changed, 2502 insertions(+), 579 deletions(-) create mode 100644 spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/WebApplication.groovy create mode 100644 spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy create mode 100644 spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/exposeall/MySecurityConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/typical/MySecurityConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/graphite/MyGraphiteConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/jmx/MyJmxConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Address.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/MyController.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Person.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Address.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/MyController.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Person.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Address.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/MyController.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Person.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/MessagingProperties.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/ServerProperties.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/ServerProperties.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/format/group/AcmeProperties.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/manualhints/valuehint/SampleProperties.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/devtools/restart/disable/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/Example.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSource.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSourceConfiguration.java rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/{CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java => spring/MyHibernateConfiguration.java} (85%) create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/Application.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/City.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/Customer.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/Endpoint.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/JerseyConfig.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/enablehttps/MySecurityConfig.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyController.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyThing.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writexmlrestservice/MyThing.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/war/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/weblogic/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilter.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/configure/MyTomcatWebServerCustomizer.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/discoverport/MyWebIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/autoconfiguration/disablingspecific/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/DatabaseAccountService.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/DatabaseAccountService.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/structuringyourcode/locatingthemainclass/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyAnotherConfig.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyConfig.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 4bb899895b..65f29639b3 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -1,5 +1,6 @@ plugins { id "java" + id "groovy" id "org.asciidoctor.jvm.convert" id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.conventions" @@ -63,12 +64,17 @@ dependencies { gradlePluginDocumentation(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "documentation")) implementation(project(path: ":spring-boot-project:spring-boot-actuator")) + implementation(project(path: ":spring-boot-project:spring-boot-actuator-autoconfigure")) implementation(project(path: ":spring-boot-project:spring-boot-autoconfigure")) + implementation(project(path: ":spring-boot-project:spring-boot-cli")) + implementation(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-loader-tools")) 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.micrometer:micrometer-registry-graphite") + implementation("io.micrometer:micrometer-registry-jmx") implementation("io.projectreactor.netty:reactor-netty-http") implementation("io.r2dbc:r2dbc-postgresql") implementation("io.undertow:undertow-core") @@ -83,6 +89,7 @@ dependencies { implementation("org.apache.tomcat.embed:tomcat-embed-core") implementation("org.assertj:assertj-core") implementation("org.glassfish.jersey.core:jersey-server") + implementation("org.glassfish.jersey.containers:jersey-container-servlet-core") implementation("org.hibernate:hibernate-jcache") implementation("org.jooq:jooq") implementation("org.mockito:mockito-core") @@ -94,14 +101,16 @@ dependencies { implementation("org.springframework:spring-orm") implementation("org.springframework:spring-test") implementation("org.springframework:spring-web") - implementation("org.springframework:spring-webmvc") implementation("org.springframework:spring-webflux") + implementation("org.springframework:spring-webmvc") + implementation("org.springframework:spring-websocket") implementation("org.springframework.amqp:spring-amqp") implementation("org.springframework.amqp:spring-rabbit") implementation("org.springframework.batch:spring-batch-core") implementation("org.springframework.data:spring-data-cassandra") implementation("org.springframework.data:spring-data-couchbase") implementation("org.springframework.data:spring-data-elasticsearch") + implementation("org.springframework.data:spring-data-jpa") implementation("org.springframework.data:spring-data-ldap") implementation("org.springframework.data:spring-data-mongodb") implementation("org.springframework.data:spring-data-neo4j") @@ -114,9 +123,12 @@ dependencies { implementation("org.springframework.restdocs:spring-restdocs-webtestclient") implementation("org.springframework.security:spring-security-config") implementation("org.springframework.security:spring-security-oauth2-client") + implementation("org.springframework.security:spring-security-test") implementation("org.springframework.security:spring-security-web") implementation("org.springframework.ws:spring-ws-core") implementation("org.springframework.ws:spring-ws-test") + implementation("org.testcontainers:junit-jupiter") + implementation("org.testcontainers:neo4j") implementation("org.junit.jupiter:junit-jupiter") implementation("org.yaml:snakeyaml") @@ -273,6 +285,9 @@ syncDocumentationSourceForAsciidoctor { from("src/test/java") { into "test/java" } + from("src/main/groovy") { + into "main/groovy" + } } syncDocumentationSourceForAsciidoctorMultipage { @@ -291,6 +306,9 @@ syncDocumentationSourceForAsciidoctorMultipage { from("src/test/java") { into "test/java" } + from("src/main/groovy") { + into "main/groovy" + } } syncDocumentationSourceForAsciidoctorPdf { @@ -309,6 +327,9 @@ syncDocumentationSourceForAsciidoctorPdf { from("src/test/java") { into "test/java" } + from("src/main/groovy") { + into "main/groovy" + } } task zip(type: Zip) { diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc index 1080c7e539..dfa44f1075 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc @@ -320,15 +320,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) -> - requests.anyRequest().hasRole("ENDPOINT_ADMIN")); - http.httpBasic(); - return http.build(); - } +include::{docs-java}/actuator/endpoints/security/typical/MySecurityConfiguration.java[] ---- The preceding example uses `EndpointRequest.toAnyEndpoint()` to match a request to any endpoint and then ensures that all have the `ENDPOINT_ADMIN` role. @@ -349,14 +343,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) -> - requests.anyRequest().permitAll()); - return http.build(); - } +include::{docs-java}/actuator/endpoints/security/exposeall/MySecurityConfiguration.java[] ---- NOTE: In both the examples above, the configuration applies only to the actuator endpoints. @@ -751,25 +740,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - import org.springframework.boot.actuate.health.Health; - import org.springframework.boot.actuate.health.HealthIndicator; - import org.springframework.stereotype.Component; - - @Component - public class MyHealthIndicator implements HealthIndicator { - - @Override - public Health health() { - int errorCode = check(); // perform some specific health check - if (errorCode != 0) { - return Health.down().withDetail("Error Code", errorCode).build(); - } - return Health.up().build(); - } - - } +include::{docs-java}/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.java[] ---- NOTE: The identifier for a given `HealthIndicator` is the name of the bean without the `HealthIndicator` suffix, if it exists. @@ -845,18 +818,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Component - public class MyReactiveHealthIndicator implements ReactiveHealthIndicator { - - @Override - public Mono health() { - return doHealthCheck() //perform some specific health check that returns a Mono - .onErrorResume(ex -> Mono.just(new Health.Builder().down(ex).build())); - } - - } +include::{docs-java}/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.java[] ---- TIP: To handle the error automatically, consider extending from `AbstractReactiveHealthIndicator`. @@ -1218,24 +1182,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - import java.util.Collections; - - import org.springframework.boot.actuate.info.Info; - import org.springframework.boot.actuate.info.InfoContributor; - import org.springframework.stereotype.Component; - - @Component - public class ExampleInfoContributor implements InfoContributor { - - @Override - public void contribute(Info.Builder builder) { - builder.withDetail("example", - Collections.singletonMap("key", "value")); - } - - } +include::{docs-java}/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java[] ---- If you reach the `info` endpoint, you should see a response that contains the following additional entry: diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc index 821bd76772..c2ee67c525 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc @@ -65,22 +65,16 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - MeterRegistryCustomizer metricsCommonTags() { - return registry -> registry.config().commonTags("region", "us-east-1"); - } +include::{docs-java}/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java ---- You can apply customizations to particular registry implementations by being more specific about the generic type: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - MeterRegistryCustomizer graphiteMetricsNamingConvention() { - return registry -> registry.config().namingConvention(MY_CUSTOM_CONVENTION); - } +include::{docs-java}/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.java ---- Spring Boot also <> that you can control via configuration or dedicated annotation markers. @@ -233,12 +227,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { - return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); - } +include::{docs-java}/actuator/metrics/export/graphite/MyGraphiteConfiguration.java ---- @@ -309,12 +300,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { - return new JmxMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); - } +include::{docs-java}/actuator/metrics/export/jmx/MyJmxConfiguration.java ---- @@ -962,55 +950,23 @@ If supported, the annotation can be used either at the class-level or the method For example, the following code shows how the annotation can be used to instrument all request mappings in a `@RestController`: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @RestController - @Timed - public class MyController { - - @GetMapping("/api/addresses") - public List listAddress() { ... } - - @GetMapping("/api/people") - public List listPeople() { ... } - - } +include::{docs-java}/actuator/metrics/supported/timedannotation/all/MyController.java[] ---- If you only want to instrument a single mapping, you can use the annotation on the method instead of the class: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @RestController - public class MyController { - - @GetMapping("/api/addresses") - public List listAddress() { ... } - - @GetMapping("/api/people") - @Timed - public List listPeople() { ... } - - } +include::{docs-java}/actuator/metrics/supported/timedannotation/single/MyController.java[] ---- You can also combine class-level and method-level annotations if you want to change timing details for a specific method: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @RestController - @Timed - public class MyController { - - @GetMapping("/api/addresses") - public List listPeople() { ... } - - @GetMapping("/api/people") - @Timed(extraTags = { "region", "us-east-1" }) - @Timed(value = "all.people", longTask = true) - public List listPeople() { ... } - - } +include::{docs-java}/actuator/metrics/supported/timedannotation/change/MyController.java[] ---- NOTE: A `@Timed` annotation with `longTask = true` will enable a long task timer for the method. 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 ea24fb4f47..a55b377b63 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 @@ -18,6 +18,7 @@ :github-issues: https://github.com/{github-repo}/issues/ :github-wiki: https://github.com/{github-repo}/wiki :docs-java: ../../main/java/org/springframework/boot/docs +:docs-groovy: ../../main/groovy/org/springframework/boot/docs :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 :spring-boot-docs: https://docs.spring.io/spring-boot/docs/{spring-boot-version}/reference diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins/other-build-systems.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins/other-build-systems.adoc index 30295b63d1..549dad9b86 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins/other-build-systems.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/build-tool-plugins/other-build-systems.adoc @@ -37,15 +37,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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - Repackager repackager = new Repackager(sourceJarFile); - repackager.setBackupSource(false); - repackager.repackage(new Libraries() { - @Override - public void doWithLibraries(LibraryCallback callback) throws IOException { - // Build system specific implementation, callback for each dependency - // callback.library(new Library(nestedFile, LibraryScope.COMPILE)); - } - }); +include::{docs-java}/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/cli/using-the-cli.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/cli/using-the-cli.adoc index ce26dd28e2..5f98b07f1c 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/cli/using-the-cli.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/cli/using-the-cli.adoc @@ -59,15 +59,7 @@ The following example shows a "`hello world`" web application written in Groovy: .hello.groovy [source,groovy,indent=0,subs="verbatim,quotes,attributes"] ---- - @RestController - class WebApplication { - - @RequestMapping("/") - String home() { - "Hello World!" - } - - } +include::{docs-groovy}/cli/usingthecli/run/WebApplication.groovy[tag=*] ---- To compile and run the application, type the following command: @@ -185,17 +177,16 @@ For example, consider the following declaration: [source,groovy,indent=0] ---- - @DependencyManagementBom("com.example.custom-bom:1.0.0") +include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy[tag=*] ---- The preceding declaration picks up `custom-bom-1.0.0.pom` in a Maven repository under `com/example/custom-versions/1.0.0/`. When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example: -[source,java,pending-extract=true,indent=0] +[source,groovy,indent=0] ---- - @DependencyManagementBom(["com.example.custom-bom:1.0.0", - "com.example.another-bom:1.0.0"]) +include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy[tag=*] ---- The preceding example indicates that the dependency management in `another-bom` overrides the dependency management in `custom-bom`. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/annotation-processor.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/annotation-processor.adoc index 993275a71f..0db8757023 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/annotation-processor.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/annotation-processor.adoc @@ -69,29 +69,9 @@ The annotation processor also supports the use of the `@Data`, `@Getter`, and `@ Consider the following example: -[source,java,pending-extract=true,indent=0,subs="verbatim,attributes"] +[source,java,indent=0,subs="verbatim,attributes"] ---- - @ConfigurationProperties(prefix="server") - public class ServerProperties { - - /** - * Name of the server. - */ - private String name; - - /** - * IP address to listen to. - */ - private String ip = "127.0.0.1"; - - /** - * Port to listener to. - */ - private int port = 9797; - - // ... getter and setters - - } +include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/ServerProperties.java[] ---- This exposes three properties where `server.name` has no default and `server.ip` and `server.port` defaults to `"127.0.0.1"` and `9797` respectively. @@ -106,25 +86,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @ConfigurationProperties(prefix = "acme.messaging") - public class MessagingProperties { - - private List addresses = new ArrayList<>(Arrays.asList("a", "b")); - - private ContainerType containerType = ContainerType.SIMPLE; - - // ... getter and setters - - public enum ContainerType { - - SIMPLE, - DIRECT - - } - - } +include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MessagingProperties.java[] ---- In order to document default values for properties in the class above, you could add the following content to <>: @@ -153,28 +117,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @ConfigurationProperties(prefix="server") - public class ServerProperties { - - private String name; - - private Host host; - - // ... getter and setters - - public static class Host { - - private String ip; - - private int port; - - // ... getter and setters - - } - - } +include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/ServerProperties.java[] ---- The preceding example produces metadata information for `server.name`, `server.host.ip`, and `server.host.port` properties. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/format.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/format.adoc index 84f5c3efc7..28c8b33f50 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/format.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/format.adoc @@ -207,28 +207,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @ConfigurationProperties("app.acme") - public class AcmeProperties { - - private String name; - - public String getName() { ... } - - public void setName(String name) { ... } - - @DeprecatedConfigurationProperty(replacement = "app.acme.name") - @Deprecated - public String getTarget() { - return getName(); - } - - @Deprecated - public void setTarget(String target) { - setName(target); - } - } +include::{docs-java}/configurationmetadata/format/group/AcmeProperties.java[] ---- NOTE: There is no way to set a `level`. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/manual-hints.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/manual-hints.adoc index 7ad151578a..c94e59f635 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/manual-hints.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/configuration-metadata/manual-hints.adoc @@ -18,14 +18,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @ConfigurationProperties("sample") - public class SampleProperties { - - private Map contexts; - // getters and setters - } +include::{docs-java}/configurationmetadata/manualhints/valuehint/SampleProperties.java[] ---- The magic values are (in this example) are `sample1` and `sample2`. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment/cloud.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment/cloud.adoc index f9e2fe3964..9ce50ac99d 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment/cloud.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment/cloud.adoc @@ -93,21 +93,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Component - class MyBean implements EnvironmentAware { - - private String instanceId; - - @Override - public void setEnvironment(Environment environment) { - this.instanceId = environment.getProperty("vcap.application.instance_id"); - } - - // ... - - } +include::{docs-java}/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java[] ---- All Cloud Foundry properties are prefixed with `vcap`. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc index 039cc5bb7f..059d9035d6 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc @@ -149,26 +149,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - import org.springframework.boot.*; - import org.springframework.boot.autoconfigure.*; - import org.springframework.web.bind.annotation.*; - - @RestController - @EnableAutoConfiguration - public class Example { - - @RequestMapping("/") - String home() { - return "Hello World!"; - } - - public static void main(String[] args) { - SpringApplication.run(Example.class, args); - } - - } +include::{docs-java}/gettingstarted/firstapplication/code/Example.java[] ---- Although there is not much code here, quite a lot is going on. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc index bbee01f721..2e3aa1f68a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc @@ -13,13 +13,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - @ConfigurationProperties(prefix="app.datasource") - public DataSource dataSource() { - return new FancyDataSource(); - } +include::{docs-java}/howto/dataaccess/configurecustomdatasource/FancyDataSourceConfiguration.java[] ---- The following example shows how to define a data source by setting properties: @@ -190,16 +186,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @EntityScan(basePackageClasses=City.class) - public class Application { - - //... - - } +include::{docs-java}/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/Application.java[] ---- @@ -255,7 +244,7 @@ This implementation provides the same table structure as Hibernate 4: all dots a [source,java,indent=0] ---- -include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java[] +include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java[] ---- If you prefer to use Hibernate 5's default instead, set the following property: @@ -267,12 +256,9 @@ If you prefer to use Hibernate 5's default instead, set the following property: Alternatively, you can configure the following bean: -[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public PhysicalNamingStrategy physicalNamingStrategy() { - return new PhysicalNamingStrategyStandardImpl(); - } +include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java[] ---- See {spring-boot-autoconfigure-module-code}/orm/jpa/HibernateJpaAutoConfiguration.java[`HibernateJpaAutoConfiguration`] and {spring-boot-autoconfigure-module-code}/orm/jpa/JpaBaseConfiguration.java[`JpaBaseConfiguration`] for more details. @@ -320,7 +306,7 @@ If you need to use JPA against multiple data sources, you likely need one `Entit The `LocalContainerEntityManagerFactoryBean` from Spring ORM allows you to configure an `EntityManagerFactory` for your needs. You can also reuse `JpaProperties` to bind settings for each `EntityManagerFactory`, as shown in the following example: -[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/CustomEntityManagerFactoryConfiguration.java[] ---- @@ -337,23 +323,16 @@ You should provide a similar configuration for any additional data sources for w To complete the picture, you need to configure a `JpaTransactionManager` for each `EntityManagerFactory` as well. Alternatively, you might be able to use a JTA transaction manager that spans both. -If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following example: +If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following examples: -[source,java,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] +---- +include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java[] ---- - @Configuration(proxyBeanMethods = false) - @EnableJpaRepositories(basePackageClasses = Order.class, - entityManagerFactoryRef = "firstEntityManagerFactory") - public class OrderConfiguration { - ... - } - @Configuration(proxyBeanMethods = false) - @EnableJpaRepositories(basePackageClasses = Customer.class, - entityManagerFactoryRef = "secondEntityManagerFactory") - public class CustomerConfiguration { - ... - } +[source,java,indent=0,subs="verbatim,quotes,attributes"] +---- +include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jersey.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jersey.adoc index 67a5471233..ff525ede80 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jersey.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/jersey.adoc @@ -24,15 +24,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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Component - public class JerseyConfig extends ResourceConfig { - - public JerseyConfig() { - register(Endpoint.class); - property(ServletProperties.FILTER_FORWARD_ON_404, true); - } - - } +include::{docs-java}/howto/jersey/alongsideanotherwebframework/JerseyConfig.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/messaging.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/messaging.adoc index 1a5dc15da8..fdb9fdae85 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/messaging.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/messaging.adoc @@ -11,19 +11,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Bean - public DefaultJmsListenerContainerFactory jmsListenerContainerFactory( - ConnectionFactory connectionFactory, - DefaultJmsListenerContainerFactoryConfigurer configurer) { - DefaultJmsListenerContainerFactory listenerFactory = - new DefaultJmsListenerContainerFactory(); - configurer.configure(listenerFactory, connectionFactory); - listenerFactory.setTransactionManager(null); - listenerFactory.setSessionTransacted(false); - return listenerFactory; - } +include::{docs-java}/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java[] ---- The preceding example overrides the default factory, and it should be applied to any other factory that your application defines, if any. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/properties-and-configuration.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/properties-and-configuration.adoc index 413fc98699..b9c3251b05 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/properties-and-configuration.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/properties-and-configuration.adoc @@ -93,7 +93,7 @@ To use Spring property placeholders together with automatic expansion, escape th [[howto.properties-and-configuration.externalize-configuration]] === Externalize the Configuration of SpringApplication -A `SpringApplication` has bean properties (mainly setters), so you can use its Java API as you create the application to modify its behavior. +A `SpringApplication` has bean property setters, so you can use its Java API as you create the application to modify its behavior. Alternatively, you can externalize the configuration by setting properties in `+spring.main.*+`. For example, in `application.properties`, you might have the following settings: @@ -107,28 +107,37 @@ For example, in `application.properties`, you might have the following settings: Then the Spring Boot banner is not printed on startup, and the application is not starting an embedded web server. -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: +Properties defined in external configuration override and replace the values specified with the Java API, with the notable exception of the primary sources. +Primary sources are those provided to the `SpringApplication` constructor: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - new SpringApplicationBuilder() - .bannerMode(Banner.Mode.OFF) - .sources(demo.MyApp.class) - .run(args); +include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java[] ---- -Now consider the following configuration: +Or to `sources(...)` method of a `SpringApplicationBuilder`: + +[source,java,indent=0] +---- +include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java[] +---- + +Given the examples above, if we have the following configuration: [source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] ---- spring: main: - sources: "com.acme.Config,com.acme.ExtraConfig" + sources: "com.example.MyDatabaseConfig,com.example.MyJmsConfig" banner-mode: "console" ---- -The actual application _now_ shows the banner (as overridden by configuration) and uses three sources for the `ApplicationContext` (in the following order): `demo.MyApp`, `com.acme.Config`, and `com.acme.ExtraConfig`. +The actual application will show the banner (as overridden by configuration) and uses three sources for the `ApplicationContext`. +The application sources are: + +.`MyApplication` (from the code) +.`MyDatabaseConfig` (from the external config) +.`MyJmsConfig`(from the external config) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/security.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/security.adoc index b15950435a..fdef188567 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/security.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/security.adoc @@ -42,12 +42,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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - // Customize the application security - http.requiresChannel().anyRequest().requiresSecure(); - return http.build(); - } +include::{docs-java}/howto/security/enablehttps/MySecurityConfig.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/spring-mvc.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/spring-mvc.adoc index ebf2c76b22..848862b925 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/spring-mvc.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/spring-mvc.adoc @@ -10,17 +10,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @RestController - public class MyController { - - @RequestMapping("/thing") - public MyThing thing() { - return new MyThing(); - } - - } +include::{docs-java}/howto/springmvc/writejsonrestservice/MyController.java[] ---- As long as `MyThing` can be serialized by Jackson2 (true for a normal POJO or Groovy object), then `http://localhost:8080/thing` serves a JSON representation of it by default. @@ -44,13 +36,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @XmlRootElement - public class MyThing { - private String name; - // .. getters and setters - } +include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[] ---- JAXB is only available out of the box with Java 8. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc index cf29279e09..acb921aa93 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testcontainers.adoc @@ -5,16 +5,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -@SpringBootTest -@Testcontainers -class ExampleIntegrationTests { - - @Container - static Neo4jContainer neo4j = new Neo4jContainer<>(); - -} +include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java ---- This will start up a docker container running Neo4j (if Docker is running locally) before any of the tests are run. @@ -22,21 +15,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- -@SpringBootTest -@Testcontainers -class ExampleIntegrationTests { - - @Container - static Neo4jContainer neo4j = new Neo4jContainer<>(); - - @DynamicPropertySource - static void neo4jProperties(DynamicPropertyRegistry registry) { - registry.add("spring.neo4j.uri", neo4j::getBoltUrl); - } - -} +include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java ---- The above configuration allows Neo4j-related beans in the application to communicate with Neo4j running inside the Testcontainers-managed Docker container. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc index 445cec7dde..c759d4b263 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/testing-with-spring-security.adoc @@ -3,15 +3,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Test - @WithMockUser(roles="ADMIN") - public void requestProtectedUrlWithUser() throws Exception { - mvc - .perform(get("/")) - ... - } +include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[] ---- Spring Security provides comprehensive integration with Spring MVC Test and this can also be used when testing controllers using the `@WebMvcTest` slice and `MockMvc`. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/traditional-deployment.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/traditional-deployment.adoc index ec65d4e9ff..a481cbfd47 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/traditional-deployment.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/traditional-deployment.adoc @@ -14,21 +14,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @SpringBootApplication - public class Application extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(Application.class); - } - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - } +include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[] ---- The next step is to update your build configuration such that your project produces a war file rather than a jar file. @@ -91,20 +79,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @SpringBootApplication - public class Application extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - // Customize the application or call application.sources(...) to add sources - // Since our example is itself a @Configuration class (via @SpringBootApplication) - // we actually don't need to override this method. - return application; - } - - } +include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=!main] ---- Remember that, whatever you put in the `sources` is merely a Spring `ApplicationContext`. @@ -124,36 +101,18 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } +include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=main] ---- [NOTE] ==== 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @SpringBootApplication - public class Application extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { - return configureApplication(builder); - } - - public static void main(String[] args) { - configureApplication(new SpringApplicationBuilder()).run(args); - } - - private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) { - return builder.sources(Application.class).bannerMode(Banner.Mode.OFF); - } - - } +include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java[] ---- ==== @@ -185,16 +144,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - import org.springframework.boot.autoconfigure.SpringBootApplication; - import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - import org.springframework.web.WebApplicationInitializer; - - @SpringBootApplication - public class MyApplication extends SpringBootServletInitializer implements WebApplicationInitializer { - - } +include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[] ---- If you use Logback, you also need to tell WebLogic to prefer the packaged version rather than the version that was pre-installed with the server. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/webserver.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/webserver.adoc index 0fc5d3a914..92d6ee4f43 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/webserver.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/webserver.adoc @@ -104,17 +104,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) - public class MyWebIntegrationTests { - - @LocalServerPort - int port; - - // ... - - } +include::{docs-java}/howto/webserver/discoverport/MyWebIntegrationTests.java[] ---- [NOTE] @@ -254,17 +246,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Component - public class MyTomcatWebServerCustomizer - implements WebServerFactoryCustomizer { - - @Override - public void customize(TomcatServletWebServerFactory factory) { - // customize the factory here - } - } +include::{docs-java}/howto/webserver/configure/MyTomcatWebServerCustomizer.java[] ---- NOTE: Spring Boot uses that infrastructure internally to auto-configure the server. @@ -335,14 +319,9 @@ 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public FilterRegistrationBean registration(MyFilter filter) { - FilterRegistrationBean registration = new FilterRegistrationBean(filter); - registration.setEnabled(false); - return registration; - } +include::{docs-java}/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java[] ---- @@ -520,12 +499,9 @@ include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/UndertowM === 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,pending-extract=true,indent=0,subs="verbatim,quotes,attributes"] +[source,java,indent=0,subs="verbatim,quotes,attributes"] ---- - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } +include::{docs-java}/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java[] ---- The bean shown in the preceding example registers any `@ServerEndpoint` annotated beans with the underlying WebSocket container. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/auto-configuration.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/auto-configuration.adoc index 73cd587fd1..d2fcc2c28a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/auto-configuration.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/auto-configuration.adoc @@ -25,14 +25,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - import org.springframework.boot.autoconfigure.*; - import org.springframework.boot.autoconfigure.jdbc.*; - - @SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) - public class MyApplication { - } +include::{docs-java}/using/autoconfiguration/disablingspecific/MyApplication.java[] ---- If the class is not on the classpath, you can use the `excludeName` attribute of the annotation and specify the fully qualified name instead. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/devtools.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/devtools.adoc index 8990ecdf66..5b621ba547 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/devtools.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/devtools.adoc @@ -162,12 +162,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - public static void main(String[] args) { - System.setProperty("spring.devtools.restart.enabled", "false"); - SpringApplication.run(MyApp.class, args); - } +include::{docs-java}/devtools/restart/disable/MyApplication.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/spring-beans-and-dependency-injection.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/spring-beans-and-dependency-injection.adoc index a0e23710e4..3184a9a813 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/spring-beans-and-dependency-injection.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/spring-beans-and-dependency-injection.adoc @@ -1,51 +1,23 @@ [[using.spring-beans-and-dependency-injection]] == Spring Beans and Dependency Injection You are free to use any of the standard Spring Framework techniques to define your beans and their injected dependencies. -We often find that using `@ComponentScan` (to find your beans) and using `@Autowired` (to do constructor injection) works well. +We generally recommend using constructor injection to wire up dependencies and `@ComponentScan` to find beans. -If you structure your code as suggested above (locating your application class in a root package), you can add `@ComponentScan` without any arguments. +If you structure your code as suggested above (locating your application class in a top package), you can add `@ComponentScan` without any arguments or use the `@SpringBootApplication` annotation which implicitly includes it. All of your application components (`@Component`, `@Service`, `@Repository`, `@Controller` etc.) are automatically registered as Spring Beans. The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - package com.example.service; - - import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.stereotype.Service; - - @Service - public class DatabaseAccountService implements AccountService { - - private final RiskAssessor riskAssessor; - - @Autowired - public DatabaseAccountService(RiskAssessor riskAssessor) { - this.riskAssessor = riskAssessor; - } - - // ... - - } +include::{docs-java}/using/springbeansanddependencyinjection/singleconstructor/DatabaseAccountService.java[] ---- -If a bean has one constructor, you can omit the `@Autowired`, as shown in the following example: +If a bean has more than one constructor, you'll need to mark the one you want Spring to use with `@Autowired`: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - @Service - public class DatabaseAccountService implements AccountService { - - private final RiskAssessor riskAssessor; - - public DatabaseAccountService(RiskAssessor riskAssessor) { - this.riskAssessor = riskAssessor; - } - - // ... - - } +include::{docs-java}/using/springbeansanddependencyinjection/multipleconstructors/DatabaseAccountService.java[] ---- TIP: Notice how using constructor injection lets the `riskAssessor` field be marked as `final`, indicating that it cannot be subsequently changed. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/structuring-your-code.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/structuring-your-code.adoc index 830e66c7f7..4af64c78d5 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/structuring-your-code.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/structuring-your-code.adoc @@ -31,7 +31,7 @@ The following listing shows a typical layout: com +- example +- myapplication - +- Application.java + +- MyApplication.java | +- customer | +- Customer.java @@ -46,21 +46,9 @@ The following listing shows a typical layout: +- OrderRepository.java ---- -The `Application.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows: +The `MyApplication.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows: -[source,java,pending-extract=true,indent=0] +[source,java,indent=0] ---- - package com.example.myapplication; - - import org.springframework.boot.SpringApplication; - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - } +include::{docs-java}/using/structuringyourcode/locatingthemainclass/MyApplication.java[] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/using-the-springbootapplication-annotation.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/using-the-springbootapplication-annotation.adoc index 423b8a9afa..b274994a98 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/using-the-springbootapplication-annotation.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/using-the-springbootapplication-annotation.adoc @@ -7,21 +7,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - package com.example.myapplication; - - import org.springframework.boot.SpringApplication; - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan - public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - } +include::{docs-java}/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java[] ---- NOTE: `@SpringBootApplication` also provides aliases to customize the attributes of `@EnableAutoConfiguration` and `@ComponentScan`. @@ -31,25 +19,9 @@ 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,pending-extract=true,indent=0] +[source,java,indent=0] ---- - package com.example.myapplication; - - import org.springframework.boot.SpringApplication; - import org.springframework.context.annotation.ComponentScan - import org.springframework.context.annotation.Configuration; - import org.springframework.context.annotation.Import; - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @Import({ MyConfig.class, MyAnotherConfig.class }) - public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - } +include::{docs-java}/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java[] ---- In this example, `Application` is just like any other Spring Boot application except that `@Component`-annotated classes and `@ConfigurationProperties`-annotated classes are not detected automatically and the user-defined beans are imported explicitly (see `@Import`). diff --git a/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/WebApplication.groovy b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/WebApplication.groovy new file mode 100644 index 0000000000..d034a7c062 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/WebApplication.groovy @@ -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.cli.usingthecli.run; + +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.RequestMapping + +// tag::code[] +@RestController +class WebApplication { + + @RequestMapping("/") + String home() { + "Hello World!" + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy new file mode 100644 index 0000000000..39d19a3c97 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy @@ -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.cli.usingthecli.run.customdependencymanagement.multiple; + +import org.springframework.boot.groovy.DependencyManagementBom; + +// tag::code[] +@DependencyManagementBom([ + "com.example.custom-bom:1.0.0", + "com.example.another-bom:1.0.0"]) +// end::code[] +class CustomDependencyManagement { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy new file mode 100644 index 0000000000..8184af3334 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/groovy/org/springframework/boot/docs/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy @@ -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.cli.usingthecli.run.customdependencymanagement.single; + +import org.springframework.boot.groovy.DependencyManagementBom; + +// tag::code[] +@DependencyManagementBom("com.example.custom-bom:1.0.0") +// end::code[] +class CustomDependencyManagement { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.java new file mode 100644 index 0000000000..ed207c5b36 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.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.actuator.endpoints.health.reactivehealthindicators; + +import reactor.core.publisher.Mono; + +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.ReactiveHealthIndicator; +import org.springframework.stereotype.Component; + +@Component +public class MyReactiveHealthIndicator implements ReactiveHealthIndicator { + + @Override + public Mono health() { + return doHealthCheck().onErrorResume((exception) -> Mono.just(new Health.Builder().down(exception).build())); + } + + private Mono doHealthCheck() { + // perform some specific health check + return /**/ null; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.java new file mode 100644 index 0000000000..492a3013c6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.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.actuator.endpoints.health.writingcustomhealthindicators; + +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Component; + +@Component +public class MyHealthIndicator implements HealthIndicator { + + @Override + public Health health() { + int errorCode = check(); + if (errorCode != 0) { + return Health.down().withDetail("Error Code", errorCode).build(); + } + return Health.up().build(); + } + + private int check() { + // perform some specific health check + return /**/ 0; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java new file mode 100644 index 0000000000..d7449af667 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java @@ -0,0 +1,33 @@ +/* + * 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.actuator.endpoints.info.writingcustominfocontributors; + +import java.util.Collections; + +import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.actuate.info.InfoContributor; +import org.springframework.stereotype.Component; + +@Component +public class MyInfoContributor implements InfoContributor { + + @Override + public void contribute(Info.Builder builder) { + builder.withDetail("example", Collections.singletonMap("key", "value")); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/exposeall/MySecurityConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/exposeall/MySecurityConfiguration.java new file mode 100644 index 0000000000..ba372dd74c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/exposeall/MySecurityConfiguration.java @@ -0,0 +1,35 @@ +/* + * 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.actuator.endpoints.security.exposeall; + +import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration(proxyBeanMethods = false) +public class MySecurityConfiguration { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.requestMatcher(EndpointRequest.toAnyEndpoint()) + .authorizeRequests((requests) -> requests.anyRequest().permitAll()); + return http.build(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/typical/MySecurityConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/typical/MySecurityConfiguration.java new file mode 100644 index 0000000000..0a963a0a6f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/endpoints/security/typical/MySecurityConfiguration.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.actuator.endpoints.security.typical; + +import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration(proxyBeanMethods = false) +public class MySecurityConfiguration { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.requestMatcher(EndpointRequest.toAnyEndpoint()) + .authorizeRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN")); + http.httpBasic(); + return http.build(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/graphite/MyGraphiteConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/graphite/MyGraphiteConfiguration.java new file mode 100644 index 0000000000..19cabff857 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/graphite/MyGraphiteConfiguration.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.actuator.metrics.export.graphite; + +import io.micrometer.core.instrument.Clock; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.config.NamingConvention; +import io.micrometer.core.instrument.util.HierarchicalNameMapper; +import io.micrometer.graphite.GraphiteConfig; +import io.micrometer.graphite.GraphiteMeterRegistry; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyGraphiteConfiguration { + + @Bean + public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { + return new GraphiteMeterRegistry(config, clock, this::toHierarchicalName); + } + + private String toHierarchicalName(Meter.Id id, NamingConvention convention) { + return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/jmx/MyJmxConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/jmx/MyJmxConfiguration.java new file mode 100644 index 0000000000..06fefff59f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/export/jmx/MyJmxConfiguration.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.actuator.metrics.export.jmx; + +import io.micrometer.core.instrument.Clock; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.config.NamingConvention; +import io.micrometer.core.instrument.util.HierarchicalNameMapper; +import io.micrometer.jmx.JmxConfig; +import io.micrometer.jmx.JmxMeterRegistry; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyJmxConfiguration { + + @Bean + public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { + return new JmxMeterRegistry(config, clock, this::toHierarchicalName); + } + + private String toHierarchicalName(Meter.Id id, NamingConvention convention) { + return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java new file mode 100644 index 0000000000..d86b46a664 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java @@ -0,0 +1,33 @@ +/* + * 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.actuator.metrics.gettingstarted.commontags; + +import io.micrometer.core.instrument.MeterRegistry; + +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyMeterRegistryConfiguration { + + @Bean + public MeterRegistryCustomizer metricsCommonTags() { + return (registry) -> registry.config().commonTags("region", "us-east-1"); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.java new file mode 100644 index 0000000000..4a5aa888d3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.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.actuator.metrics.gettingstarted.specifictype; + +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.config.NamingConvention; +import io.micrometer.graphite.GraphiteMeterRegistry; + +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyMeterRegistryConfiguration { + + @Bean + MeterRegistryCustomizer graphiteMetricsNamingConvention() { + return (registry) -> registry.config().namingConvention(this::name); + } + + private String name(String name, Meter.Type type, String baseUnit) { + return /**/ NamingConvention.snakeCase.name(name, type, baseUnit); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Address.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Address.java new file mode 100644 index 0000000000..7b074590c1 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Address.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all; + +class Address { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/MyController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/MyController.java new file mode 100644 index 0000000000..772a173047 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/MyController.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.actuator.metrics.supported.timedannotation.all; + +import java.util.List; + +import io.micrometer.core.annotation.Timed; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Timed +public class MyController { + + @GetMapping("/api/addresses") + public List
listAddress() { + return /**/ null; + } + + @GetMapping("/api/people") + public List listPeople() { + return /**/ null; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Person.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Person.java new file mode 100644 index 0000000000..ecdeef4509 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/all/Person.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all; + +class Person { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Address.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Address.java new file mode 100644 index 0000000000..818cd770dc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Address.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change; + +class Address { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/MyController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/MyController.java new file mode 100644 index 0000000000..a9579e4b71 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/MyController.java @@ -0,0 +1,42 @@ +/* + * 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.actuator.metrics.supported.timedannotation.change; + +import java.util.List; + +import io.micrometer.core.annotation.Timed; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Timed +public class MyController { + + @GetMapping("/api/addresses") + public List
listAddress() { + return /**/ null; + } + + @GetMapping("/api/people") + @Timed(extraTags = { "region", "us-east-1" }) + @Timed(value = "all.people", longTask = true) + public List listPeople() { + return /**/ null; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Person.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Person.java new file mode 100644 index 0000000000..e954534481 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/change/Person.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change; + +class Person { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Address.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Address.java new file mode 100644 index 0000000000..7427941959 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Address.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single; + +class Address { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/MyController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/MyController.java new file mode 100644 index 0000000000..f5822c2b26 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/MyController.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.actuator.metrics.supported.timedannotation.single; + +import java.util.List; + +import io.micrometer.core.annotation.Timed; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MyController { + + @GetMapping("/api/addresses") + public List
listAddress() { + return /**/ null; + } + + @GetMapping("/api/people") + @Timed + public List listPeople() { + return /**/ null; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Person.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Person.java new file mode 100644 index 0000000000..9eb03399a0 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/metrics/supported/timedannotation/single/Person.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. + */ + +package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single; + +class Person { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java new file mode 100644 index 0000000000..311a5ed933 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java @@ -0,0 +1,49 @@ +/* + * 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.buildtoolplugins.otherbuildsystems.examplerepackageimplementation; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.springframework.boot.loader.tools.Library; +import org.springframework.boot.loader.tools.LibraryCallback; +import org.springframework.boot.loader.tools.LibraryScope; +import org.springframework.boot.loader.tools.Repackager; + +public class MyBuildTool { + + public void build() throws IOException { + File sourceJarFile = /**/ null; + Repackager repackager = new Repackager(sourceJarFile); + repackager.setBackupSource(false); + repackager.repackage(this::getLibraries); + } + + private void getLibraries(LibraryCallback callback) throws IOException { + // Build system specific implementation, callback for each dependency + for (File nestedJar : getCompileScopeJars()) { + callback.library(new Library(nestedJar, LibraryScope.COMPILE)); + } + // ... + } + + private List getCompileScopeJars() { + return /**/ null; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/MessagingProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/MessagingProperties.java new file mode 100644 index 0000000000..a2d331d893 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/MessagingProperties.java @@ -0,0 +1,56 @@ +/* + * 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.configurationmetadata.annotationprocessor.automaticmetadatageneration; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "acme.messaging") +public class MessagingProperties { + + private List addresses = new ArrayList<>(Arrays.asList("a", "b")); + + private ContainerType containerType = ContainerType.SIMPLE; + + // @fold:on // getters/setters ... + public List getAddresses() { + return this.addresses; + } + + public void setAddresses(List addresses) { + this.addresses = addresses; + } + + public ContainerType getContainerType() { + return this.containerType; + } + + public void setContainerType(ContainerType containerType) { + this.containerType = containerType; + } + // @fold:off + + public enum ContainerType { + + SIMPLE, DIRECT + + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/ServerProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/ServerProperties.java new file mode 100644 index 0000000000..4a23fa90fb --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/ServerProperties.java @@ -0,0 +1,65 @@ +/* + * 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.configurationmetadata.annotationprocessor.automaticmetadatageneration; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "server") +public class ServerProperties { + + /** + * Name of the server. + */ + private String name; + + /** + * IP address to listen to. + */ + private String ip = "127.0.0.1"; + + /** + * Port to listener to. + */ + private int port = 9797; + + // @fold:on // getters/setters ... + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIp() { + return this.ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getPort() { + return this.port; + } + + public void setPort(int port) { + this.port = port; + } + // fold:off + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/ServerProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/ServerProperties.java new file mode 100644 index 0000000000..851b1d5290 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/ServerProperties.java @@ -0,0 +1,72 @@ +/* + * 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.configurationmetadata.annotationprocessor.automaticmetadatageneration.nestedproperties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "server") +public class ServerProperties { + + private String name; + + private Host host; + + // @fold:on // getters/setters ... + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Host getHost() { + return this.host; + } + + public void setHost(Host host) { + this.host = host; + } + // @fold:off + + public static class Host { + + private String ip; + + private int port; + + // @fold:on // getters/setters ... + public String getIp() { + return this.ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getPort() { + return this.port; + } + + public void setPort(int port) { + this.port = port; + } + // @fold:off // getters/setters ... + + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/format/group/AcmeProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/format/group/AcmeProperties.java new file mode 100644 index 0000000000..ede19c7edc --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/format/group/AcmeProperties.java @@ -0,0 +1,46 @@ +/* + * 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.configurationmetadata.format.group; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; + +@ConfigurationProperties("app.acme") +public class AcmeProperties { + + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Deprecated + @DeprecatedConfigurationProperty(replacement = "app.acme.name") + public String getTarget() { + return this.name; + } + + @Deprecated + public void setTarget(String target) { + this.name = target; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/manualhints/valuehint/SampleProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/manualhints/valuehint/SampleProperties.java new file mode 100644 index 0000000000..326e01e16f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/configurationmetadata/manualhints/valuehint/SampleProperties.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.configurationmetadata.manualhints.valuehint; + +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("sample") +public class SampleProperties { + + private Map contexts; + + // @fold:on // getters/setters ... + public Map getContexts() { + return this.contexts; + } + + public void setContexts(Map contexts) { + this.contexts = contexts; + } + // @fold:off + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java new file mode 100644 index 0000000000..af31d13675 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.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.deployment.cloud.cloudfoundry.bindingtoservices; + +import org.springframework.context.EnvironmentAware; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +class MyBean implements EnvironmentAware { + + @SuppressWarnings("unused") + private String instanceId; + + @Override + public void setEnvironment(Environment environment) { + this.instanceId = environment.getProperty("vcap.application.instance_id"); + } + + // ... + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/devtools/restart/disable/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/devtools/restart/disable/MyApplication.java new file mode 100644 index 0000000000..44bc253f1a --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/devtools/restart/disable/MyApplication.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.devtools.restart.disable; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyApplication { + + public static void main(String[] args) { + System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(MyApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/Example.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/Example.java new file mode 100644 index 0000000000..38111e0496 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/Example.java @@ -0,0 +1,37 @@ +/* + * 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.gettingstarted.firstapplication.code; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@EnableAutoConfiguration +public class Example { + + @RequestMapping("/") + String home() { + return "Hello World!"; + } + + public static void main(String[] args) { + SpringApplication.run(Example.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSource.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSource.java new file mode 100644 index 0000000000..ad3beeac47 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSource.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. + */ + +package org.springframework.boot.docs.howto.dataaccess.configurecustomdatasource; + +public class FancyDataSource { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSourceConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSourceConfiguration.java new file mode 100644 index 0000000000..b871a92a05 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurecustomdatasource/FancyDataSourceConfiguration.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.howto.dataaccess.configurecustomdatasource; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +public class FancyDataSourceConfiguration { + + @Bean + @ConfigurationProperties(prefix = "app.datasource") + public FancyDataSource dataSource() { + return new FancyDataSource(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java index 79e90aa110..c82b766fdf 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.howto.dataaccess.configurehibernatenamingstrategy; +package org.springframework.boot.docs.howto.dataaccess.configurehibernatenamingstrategy.spring; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; @@ -22,11 +22,11 @@ import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -@Configuration -class CaseSensitiveSpringPhysicalNamingStrategyConfiguration { +@Configuration(proxyBeanMethods = false) +public class MyHibernateConfiguration { @Bean - SpringPhysicalNamingStrategy caseSensitivePhysicalNamingStrategy() { + public SpringPhysicalNamingStrategy caseSensitivePhysicalNamingStrategy() { return new SpringPhysicalNamingStrategy() { @Override diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java new file mode 100644 index 0000000000..67ffd07369 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.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.howto.dataaccess.configurehibernatenamingstrategy.standard; + +import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +class MyHibernateConfiguration { + + @Bean + PhysicalNamingStrategyStandardImpl caseSensitivePhysicalNamingStrategy() { + return new PhysicalNamingStrategyStandardImpl(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/Application.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/Application.java new file mode 100644 index 0000000000..91eb02e6a4 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/Application.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.howto.dataaccess.separateentitydefinitionsfromspringconfiguration; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@EntityScan(basePackageClasses = City.class) +public class Application { + + // ... + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/City.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/City.java new file mode 100644 index 0000000000..b9c9790020 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/City.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. + */ + +package org.springframework.boot.docs.howto.dataaccess.separateentitydefinitionsfromspringconfiguration; + +class City { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomEntityManagerFactoryConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomEntityManagerFactoryConfiguration.java index 79ad568ff2..6f917c0af2 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomEntityManagerFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomEntityManagerFactoryConfiguration.java @@ -49,7 +49,7 @@ public class CustomEntityManagerFactoryConfiguration { } private JpaVendorAdapter createJpaVendorAdapter(JpaProperties jpaProperties) { - // Map JPA properties as needed + // ... map JPA properties as needed return new HibernateJpaVendorAdapter(); } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/Customer.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/Customer.java new file mode 100644 index 0000000000..b03ad31d27 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/Customer.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. + */ + +package org.springframework.boot.docs.howto.dataaccess.usemultipleentitymanagers; + +public class Customer { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java new file mode 100644 index 0000000000..6092d4c32b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.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.howto.dataaccess.usemultipleentitymanagers; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@Configuration(proxyBeanMethods = false) +@EnableJpaRepositories(basePackageClasses = Customer.class, entityManagerFactoryRef = "secondEntityManagerFactory") +public class CustomerConfiguration { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java new file mode 100644 index 0000000000..72f00ba0fb --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.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.howto.dataaccess.usemultipleentitymanagers; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@Configuration(proxyBeanMethods = false) +@EnableJpaRepositories(basePackageClasses = Order.class, entityManagerFactoryRef = "firstEntityManagerFactory") +public class OrderConfiguration { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/Endpoint.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/Endpoint.java new file mode 100644 index 0000000000..8a9e8579be --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/Endpoint.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. + */ + +package org.springframework.boot.docs.howto.jersey.alongsideanotherwebframework; + +class Endpoint { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/JerseyConfig.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/JerseyConfig.java new file mode 100644 index 0000000000..b64eae6ff3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/alongsideanotherwebframework/JerseyConfig.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.howto.jersey.alongsideanotherwebframework; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; + +import org.springframework.stereotype.Component; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + register(Endpoint.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java new file mode 100644 index 0000000000..b11cb79126 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.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.messaging.disabletransactedjmssession; + +import javax.jms.ConnectionFactory; + +import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jms.config.DefaultJmsListenerContainerFactory; + +@Configuration(proxyBeanMethods = false) +public class MyJmsConfiguration { + + @Bean + public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory, + DefaultJmsListenerContainerFactoryConfigurer configurer) { + DefaultJmsListenerContainerFactory listenerFactory = new DefaultJmsListenerContainerFactory(); + configurer.configure(listenerFactory, connectionFactory); + listenerFactory.setTransactionManager(null); + listenerFactory.setSessionTransacted(false); + return listenerFactory; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java new file mode 100644 index 0000000000..7df228f5e2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.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.howto.propertiesandconfiguration.externalizeconfiguration.application; + +import org.springframework.boot.Banner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyApplication { + + public static void main(String[] args) { + SpringApplication application = new SpringApplication(MyApplication.class); + application.setBannerMode(Banner.Mode.OFF); + application.run(args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java new file mode 100644 index 0000000000..ebb33d2452 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java @@ -0,0 +1,33 @@ +/* + * 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.propertiesandconfiguration.externalizeconfiguration.builder; + +import org.springframework.boot.Banner; +import org.springframework.boot.builder.SpringApplicationBuilder; + +public class MyApplication { + + public static void main(String[] args) { + // @formatter:off + new SpringApplicationBuilder() + .bannerMode(Banner.Mode.OFF) + .sources(MyApplication.class) + .run(args); + // @formatter:on + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/enablehttps/MySecurityConfig.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/enablehttps/MySecurityConfig.java new file mode 100644 index 0000000000..a02a677ea6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/security/enablehttps/MySecurityConfig.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.howto.security.enablehttps; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +public class MySecurityConfig { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + // Customize the application security ... + http.requiresChannel().anyRequest().requiresSecure(); + return http.build(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyController.java new file mode 100644 index 0000000000..43e03a9d8e --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyController.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.howto.springmvc.writejsonrestservice; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MyController { + + @RequestMapping("/thing") + public MyThing thing() { + return new MyThing(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyThing.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyThing.java new file mode 100644 index 0000000000..ed28185e30 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writejsonrestservice/MyThing.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. + */ + +package org.springframework.boot.docs.howto.springmvc.writejsonrestservice; + +public class MyThing { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writexmlrestservice/MyThing.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writexmlrestservice/MyThing.java new file mode 100644 index 0000000000..7b69c1ee62 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springmvc/writexmlrestservice/MyThing.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.howto.springmvc.writexmlrestservice; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class MyThing { + + private String name; + + // @fold:on // getters/setters ... + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + // @fold:off + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.java new file mode 100644 index 0000000000..55ee89faa3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/dynamicproperties/MyIntegrationTests.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.testcontainers.dynamicproperties; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.Neo4jContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +@SpringBootTest +@Testcontainers +class MyIntegrationTests { + + @Container + static Neo4jContainer neo4j = new Neo4jContainer<>("neo4j:4.2"); + + @Test + void myTest() { + // ... + } + + @DynamicPropertySource + static void neo4jProperties(DynamicPropertyRegistry registry) { + registry.add("spring.neo4j.uri", neo4j::getBoltUrl); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.java new file mode 100644 index 0000000000..454b2f0cb1 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testcontainers/vanilla/MyIntegrationTests.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.testcontainers.vanilla; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.Neo4jContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +@Testcontainers +class MyIntegrationTests { + + @Container + static Neo4jContainer neo4j = new Neo4jContainer<>("neo4j:4.2"); + + @Test + void myTest() { + // ... + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.java new file mode 100644 index 0000000000..0a5227ccdf --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/MySecurityTests.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.howto.testingwithspringsecurity; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; + +@WebMvcTest(UserController.class) +public class MySecurityTests { + + @Autowired + private MockMvc mvc; + + @Test + @WithMockUser(roles = "ADMIN") + void requestProtectedUrlWithUser() throws Exception { + this.mvc.perform(get("/")); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.java new file mode 100644 index 0000000000..19e24c032b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/testingwithspringsecurity/UserController.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. + */ + +package org.springframework.boot.docs.howto.testingwithspringsecurity; + +class UserController { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/MyApplication.java new file mode 100644 index 0000000000..ec886c4f59 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/MyApplication.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.howto.traditionaldeployment.convertexistingapplication; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class MyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + // Customize the application or call application.sources(...) to add sources + // Since our example is itself a @Configuration class (via @SpringBootApplication) + // we actually don't need to override this method. + return application; + } + + // tag::main[] + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + // end::main[] + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java new file mode 100644 index 0000000000..1967af66f9 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.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.howto.traditionaldeployment.convertexistingapplication.both; + +import org.springframework.boot.Banner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class MyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return customizerBuilder(builder); + } + + public static void main(String[] args) { + customizerBuilder(new SpringApplicationBuilder()).run(args); + } + + private static SpringApplicationBuilder customizerBuilder(SpringApplicationBuilder builder) { + return builder.sources(MyApplication.class).bannerMode(Banner.Mode.OFF); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/war/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/war/MyApplication.java new file mode 100644 index 0000000000..bb8164ff7d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/war/MyApplication.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.howto.traditionaldeployment.war; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class MyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(MyApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/weblogic/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/weblogic/MyApplication.java new file mode 100644 index 0000000000..b46e47be68 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/traditionaldeployment/weblogic/MyApplication.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.howto.traditionaldeployment.weblogic; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.web.WebApplicationInitializer; + +@SpringBootApplication +public class MyApplication extends SpringBootServletInitializer implements WebApplicationInitializer { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilter.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilter.java new file mode 100644 index 0000000000..9c448efa72 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilter.java @@ -0,0 +1,23 @@ +/* + * 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.webserver.addservletfilterlistener.springbean.disable; + +import javax.servlet.Filter; + +public abstract class MyFilter implements Filter { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java new file mode 100644 index 0000000000..bc728ac53f --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java @@ -0,0 +1,33 @@ +/* + * 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.webserver.addservletfilterlistener.springbean.disable; + +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyFilterConfiguration { + + @Bean + public FilterRegistrationBean registration(MyFilter filter) { + FilterRegistrationBean registration = new FilterRegistrationBean<>(filter); + registration.setEnabled(false); + return registration; + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/configure/MyTomcatWebServerCustomizer.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/configure/MyTomcatWebServerCustomizer.java new file mode 100644 index 0000000000..14df9fc80b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/configure/MyTomcatWebServerCustomizer.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.howto.webserver.configure; + +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; + +@Component +public class MyTomcatWebServerCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(TomcatServletWebServerFactory factory) { + // customize the factory here + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java new file mode 100644 index 0000000000..63948c342b --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.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.howto.webserver.createwebsocketendpointsusingserverendpoint; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration(proxyBeanMethods = false) +public class MyWebSocketConfiguration { + + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/discoverport/MyWebIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/discoverport/MyWebIntegrationTests.java new file mode 100644 index 0000000000..520e6e3b1a --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/discoverport/MyWebIntegrationTests.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.howto.webserver.discoverport; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class MyWebIntegrationTests { + + @LocalServerPort + int port; + + // ... + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/autoconfiguration/disablingspecific/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/autoconfiguration/disablingspecific/MyApplication.java new file mode 100644 index 0000000000..8288ceb90d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/autoconfiguration/disablingspecific/MyApplication.java @@ -0,0 +1,25 @@ +/* + * 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.using.autoconfiguration.disablingspecific; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +public class MyApplication { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.java new file mode 100644 index 0000000000..7a7f367207 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.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. + */ + +package org.springframework.boot.docs.using.springbeansanddependencyinjection.multipleconstructors; + +public interface AccountService { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/DatabaseAccountService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/DatabaseAccountService.java new file mode 100644 index 0000000000..fe314ec061 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/DatabaseAccountService.java @@ -0,0 +1,46 @@ +/* + * 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.using.springbeansanddependencyinjection.multipleconstructors; + +import java.io.PrintStream; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class DatabaseAccountService implements AccountService { + + @SuppressWarnings("unused") + private final RiskAssessor riskAssessor; + + @SuppressWarnings("unused") + private final PrintStream out; + + @Autowired + public DatabaseAccountService(RiskAssessor riskAssessor) { + this.riskAssessor = riskAssessor; + this.out = System.out; + } + + public DatabaseAccountService(RiskAssessor riskAssessor, PrintStream out) { + this.riskAssessor = riskAssessor; + this.out = out; + } + + // ... + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.java new file mode 100644 index 0000000000..fcc89452d6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.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. + */ + +package org.springframework.boot.docs.using.springbeansanddependencyinjection.multipleconstructors; + +public interface RiskAssessor { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.java new file mode 100644 index 0000000000..676d061fa9 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.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. + */ + +package org.springframework.boot.docs.using.springbeansanddependencyinjection.singleconstructor; + +public interface AccountService { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/DatabaseAccountService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/DatabaseAccountService.java new file mode 100644 index 0000000000..48b0ecd3a7 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/DatabaseAccountService.java @@ -0,0 +1,33 @@ +/* + * 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.using.springbeansanddependencyinjection.singleconstructor; + +import org.springframework.stereotype.Service; + +@Service +public class DatabaseAccountService implements AccountService { + + @SuppressWarnings("unused") + private final RiskAssessor riskAssessor; + + public DatabaseAccountService(RiskAssessor riskAssessor) { + this.riskAssessor = riskAssessor; + } + + // ... + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.java new file mode 100644 index 0000000000..7a55aea32a --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.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. + */ + +package org.springframework.boot.docs.using.springbeansanddependencyinjection.singleconstructor; + +public interface RiskAssessor { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/structuringyourcode/locatingthemainclass/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/structuringyourcode/locatingthemainclass/MyApplication.java new file mode 100644 index 0000000000..38542621e4 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/structuringyourcode/locatingthemainclass/MyApplication.java @@ -0,0 +1,29 @@ +/* + * 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.using.structuringyourcode.locatingthemainclass; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyApplication { + + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyAnotherConfig.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyAnotherConfig.java new file mode 100644 index 0000000000..05502c9d28 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyAnotherConfig.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. + */ + +package org.springframework.boot.docs.using.usingthespringbootapplicationannotation.individualannotations; + +public class MyAnotherConfig { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java new file mode 100644 index 0000000000..ba27831866 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java @@ -0,0 +1,33 @@ +/* + * 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.using.usingthespringbootapplicationannotation.individualannotations; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@Import({ MyConfig.class, MyAnotherConfig.class }) +public class MyApplication { + + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyConfig.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyConfig.java new file mode 100644 index 0000000000..3052ea8da3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/MyConfig.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. + */ + +package org.springframework.boot.docs.using.usingthespringbootapplicationannotation.individualannotations; + +public class MyConfig { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java new file mode 100644 index 0000000000..5bea9d3306 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java @@ -0,0 +1,29 @@ +/* + * 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.using.usingthespringbootapplicationannotation.springapplication; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan +public class MyApplication { + + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + +} diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index e41553202f..8b2f24cef1 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -17,7 +17,7 @@ - +