### Cloud Foundry deployment output Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example output from `cf push` showing the upload, buildpack download, and app startup. The output indicates the app is started when '1 of 1 instances running' appears. ```text Uploading acloudyspringtime... **OK** Preparing to start acloudyspringtime... **OK** -----> Downloaded app package (**8.9M**) -----> Java Buildpack Version: v3.12 (offline) | https://github.com/cloudfoundry/java-buildpack.git#6f25b7e -----> Downloading Open Jdk JRE 1.8.0_121 from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_121.tar.gz (found in cache) Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.6s) -----> Downloading Open JDK Like Memory Calculator 2.0.2_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/trusty/x86_64/memory-calculator-2.0.2_RELEASE.tar.gz (found in cache) Memory Settings: -Xss349K -Xmx681574K -XX:MaxMetaspaceSize=104857K -Xms681574K -XX:MetaspaceSize=104857K -----> Downloading Container Certificate Trust Store 1.0.0_RELEASE from https://java-buildpack.cloudfoundry.org/container-certificate-trust-store/container-certificate-trust-store-1.0.0_RELEASE.jar (found in cache) Adding certificates to .java-buildpack/container_certificate_trust_store/truststore.jks (0.6s) -----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache) Checking status of app 'acloudyspringtime'... 0 of 1 instances running (1 starting) ... 0 of 1 instances running (1 starting) ... 0 of 1 instances running (1 starting) ... 1 of 1 instances running (1 running) App started ``` -------------------------------- ### Spring Boot startup log output Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example output when a Spring Boot application starts, showing the banner and INFO log messages including the user, Java version, and Tomcat startup. ```text . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.18) 2023-11-23 07:23:23.238 INFO 28579 --- [ main] o.s.b.d.f.logexample.MyApplication : Starting MyApplication using Java 1.8.0_392 on myhost with PID 28579 (/opt/apps/myapp.jar started by myuser in /opt/apps/) 2023-11-23 07:23:23.245 INFO 28579 --- [ main] o.s.b.d.f.logexample.MyApplication : No active profile set, falling back to 1 default profile: "default" 2023-11-23 07:23:24.552 INFO 28579 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2023-11-23 07:23:24.567 INFO 28579 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2023-11-23 07:23:24.567 INFO 28579 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.83] 2023-11-23 07:23:24.658 INFO 28579 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2023-11-23 07:23:24.659 INFO 28579 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1346 ms 2023-11-23 07:23:25.336 INFO 28579 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2023-11-23 07:23:25.355 INFO 28579 --- [ main] o.s.b.d.f.logexample.MyApplication : Started MyApplication in 2.63 seconds (JVM running for 3.003) ``` -------------------------------- ### cf apps output Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example output from `cf apps` showing the deployed application `acloudyspringtime` with status `started` and its URL. ```text Getting applications in ... OK name requested state instances memory disk urls ... acloudyspringtime started 1/1 512M 1G acloudyspringtime.cfapps.io ... ``` -------------------------------- ### Inject WebClient.Builder and call REST service (Kotlin) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin version of the typical WebClient example, using the auto-configured WebClient.Builder to create a client and make a reactive GET request. ```kotlin import org.neo4j.cypherdsl.core.Relationship import org.springframework.stereotype.Service import org.springframework.web.reactive.function.client.WebClient import reactor.core.publisher.Mono @Service class MyService(webClientBuilder: WebClient.Builder) { private val webClient: WebClient init { webClient = webClientBuilder.baseUrl("https://example.org").build() } fun someRestCall(name: String?): Mono { return webClient.get().uri("/{name}/details", name).retrieve().bodyToMono( Relationship.Details::class.java ) } } ``` -------------------------------- ### Start init.d service Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Command to start the init.d service on a Debian-based system. If the application fails to start, check the log file at /var/log/.log. ```bash $ service myapp start ``` -------------------------------- ### Kotlin @ConfigurationProperties example for AcmeProperties Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin example showing how to document configuration keys with field Javadoc. Use a unique namespace (e.g., 'acme') and add Javadoc comments for each property. The example includes boolean and Duration fields. ```kotlin import org.springframework.boot.context.properties.ConfigurationProperties import java.time.Duration @ConfigurationProperties("acme") class AcmeProperties( /** * Whether to check the location of acme resources. */ var isCheckLocation: Boolean = true, /** * Timeout for establishing a connection to the acme server. */ var loginTimeout:Duration = Duration.ofSeconds(3)) ``` -------------------------------- ### YAML list example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example YAML document with a list under 'my.servers' that will be flattened using index dereferencers. ```yaml my: servers: - "dev.example.com" - "another.example.com" ``` -------------------------------- ### Java @Profile example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Java example of a @Configuration class annotated with @Profile to load only in the 'production' profile. ```java import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @Configuration(proxyBeanMethods = false) @Profile("production") public class ProductionConfiguration { // ... } ``` -------------------------------- ### Equivalent application.properties for YAML example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Properties file that corresponds to the preceding YAML example, showing the flattened keys with period-separated names. ```properties spring.application.name=cruncher spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost/test server.port=9000 ``` -------------------------------- ### Java @ConfigurationProperties example for AcmeProperties Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Java example showing how to document configuration keys with field Javadoc. Use a unique namespace (e.g., 'acme') and add Javadoc comments for each property. The example includes boolean and Duration fields with getters and setters. ```java import java.time.Duration; import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("acme") public class AcmeProperties { /** * Whether to check the location of acme resources. */ private boolean checkLocation = true; /** * Timeout for establishing a connection to the acme server. */ private Duration loginTimeout = Duration.ofSeconds(3); // getters/setters ... public boolean isCheckLocation() { return this.checkLocation; } public void setCheckLocation(boolean checkLocation) { this.checkLocation = checkLocation; } public Duration getLoginTimeout() { return this.loginTimeout; } public void setLoginTimeout(Duration loginTimeout) { this.loginTimeout = loginTimeout; } } ``` -------------------------------- ### Kotlin @Profile example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin example of a @Configuration class annotated with @Profile to load only in the 'production' profile. ```kotlin import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Profile @Configuration(proxyBeanMethods = false) @Profile("production") class ProductionConfiguration { // ... } ``` -------------------------------- ### Install Spring Boot CLI dev instance with SDKMAN! Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Installs a local 'dev' instance of the Spring Boot CLI pointing to a target build location, sets it as default, and verifies the version. Every rebuild updates the 'spring' command. ```bash $ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.7.18-bin/spring-2.7.18/ $ sdk default springboot dev $ spring --version Spring CLI v2.7.18 ``` -------------------------------- ### YAML configuration for list merging example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle YAML version of the list merging example, showing the same behavior. ```yaml my: list: - name: "my name" description: "my description" --- spring: config: activate: on-profile: "dev" my: list: - name: "my another name" ``` -------------------------------- ### Set init.d service to start on boot Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Command to configure the init.d service to start automatically on boot using update-rc.d on Debian. ```bash $ update-rc.d myapp defaults ``` -------------------------------- ### Tomcat WebServerFactoryCustomizer example (Kotlin) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin version of the Tomcat WebServerFactoryCustomizer example. Declare a component and customize the TomcatServletWebServerFactory inside the customize method. ```kotlin import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory import org.springframework.boot.web.server.WebServerFactoryCustomizer import org.springframework.stereotype.Component @Component class MyTomcatWebServerCustomizer : WebServerFactoryCustomizer { ``` -------------------------------- ### SpringApplicationBuilder fluent API example (Kotlin) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin version of the SpringApplicationBuilder example, using Kotlin class references and the spread operator for arguments. ```Kotlin SpringApplicationBuilder() .sources(Parent::class.java) .child(Application::class.java) .bannerMode(Banner.Mode.OFF) .run(*args) ``` -------------------------------- ### Configuration metadata JSON example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows the structure of a Spring Boot configuration metadata JSON file with 'properties', 'groups', and 'hints' arrays. The example includes a property for 'spring.jpa.hibernate.ddl-auto' with its description and source type, and hints for its possible values. ```json { "properties": [ { "name": "spring.jpa.hibernate.ddl-auto", "type": "java.lang.String", "description": "DDL mode. This is actually a shortcut for the \"hibernate.hbm2ddl.auto\" property.", "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate" } ], ... ],"hints": [ { "name": "spring.jpa.hibernate.ddl-auto", "values": [ { "value": "none", "description": "Disable DDL handling." }, { "value": "validate", "description": "Validate the schema, make no changes to the database." }, { "value": "update", "description": "Update the schema if necessary." }, { "value": "create", "description": "Create the schema and destroy previous data." }, { "value": "create-drop", "description": "Create and then destroy the schema at the end of the session." } ] } ]} ``` -------------------------------- ### List capabilities with spring init --list Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Lists the available dependencies and project types from start.spring.io. The output is truncated in the example. ```bash $ spring init --list ======================================= Capabilities of https://start.spring.io ======================================= Available dependencies: ----------------------- actuator - Actuator: Production ready features to help you monitor and manage your application ... web - Web: Support for full-stack web development, including Tomcat and spring-webmvc websocket - Websocket: Support for WebSocket development ws - WS: Support for Spring Web Services Available project types: ------------------------ gradle-build - Gradle Config [format:build, build:gradle] gradle-project - Gradle Project [format:project, build:gradle] maven-build - Maven POM [format:build, build:maven] maven-project - Maven Project [format:project, build:maven] (default) ... ``` -------------------------------- ### Configure CORS for Actuator endpoints (Properties) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Enable CORS by setting allowed-origins and allowed-methods. This example permits GET and POST from example.com. CORS is disabled by default until allowed-origins is set. ```properties management.endpoints.web.cors.allowed-origins=https://example.com management.endpoints.web.cors.allowed-methods=GET,POST ``` -------------------------------- ### YAML configuration example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows how to set the 'server.port' and 'server.address' properties in an 'application.yaml' file. ```yaml server: port: 9090 address: 127.0.0.1 ``` -------------------------------- ### Properties configuration example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows how to set the 'server.port' and 'server.address' properties in an 'application.properties' file. ```properties server.port=9090 server.address=127.0.0.1 ``` -------------------------------- ### Initialize a new project with spring init Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Creates a new project using start.spring.io. The example creates a Maven-based project with web and data-jpa dependencies. ```bash $ spring init --dependencies=web,data-jpa my-project Using service at https://start.spring.io Project extracted to '/Users/developer/example/my-project' ``` -------------------------------- ### Default Spring Security generated password output Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example output showing the generated security password printed at WARN level when the application starts. The password is random and for development use only. ```text Using generated security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35 This generated password is for development use only. Your security configuration must be updated before running your application in production. ``` -------------------------------- ### Any provider example for system.state Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Offers 'on' and 'off' as auto-completion values for 'system.state' using the 'any' provider. Any other value is also allowed. ```json {"hints": [ { "name": "system.state", "values": [ { "value": "on" }, { "value": "off" } ], "providers": [ { "name": "any" } ] } ]} ``` -------------------------------- ### Inject WebClient.Builder and call REST service (Java) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Typical example of injecting the auto-configured WebClient.Builder and using it to create a WebClient with a base URL, then making a GET request to retrieve details as a Mono. ```java import org.neo4j.cypherdsl.core.Relationship.Details; import reactor.core.publisher.Mono; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; @Service public class MyService { private final WebClient webClient; public MyService(WebClient.Builder webClientBuilder) { this.webClient = webClientBuilder.baseUrl("https://example.org").build(); } public Mono
someRestCall(String name) { return this.webClient.get().uri("/{name}/details", name).retrieve().bodyToMono(Details.class); } } ``` -------------------------------- ### Quick-start Spring CLI example: app.groovy Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle A simple Groovy web application that returns 'Hello World!' at the root path. Run it with 'spring run app.groovy' and open localhost:8080. ```groovy @RestController class ThisWillActuallyRun { @RequestMapping("/") String home() { "Hello World!" } } ``` -------------------------------- ### Run the Spring CLI example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Runs the app.groovy file using the Spring CLI. The first run is slow because dependencies are downloaded. ```bash $ spring run app.groovy ``` -------------------------------- ### Call RSocket service with RSocketRequester (Kotlin) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Kotlin example of a service that uses RSocketRequester.Builder to create a TCP connection and call an RSocket route. The builder is a prototype bean, so each injection point gets a new instance. ```kotlin import org.springframework.messaging.rsocket.RSocketRequester import org.springframework.stereotype.Service import reactor.core.publisher.Mono @Service class MyService(rsocketRequesterBuilder: RSocketRequester.Builder) { private val rsocketRequester: RSocketRequester init { rsocketRequester = rsocketRequesterBuilder.tcp("example.org", 9898) } fun someRSocketCall(name: String): Mono { return rsocketRequester.route("user").data(name).retrieveMono( User::class.java ) } } ``` -------------------------------- ### Create a Gradle project with spring init Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Creates a Gradle project with Java 8 and war packaging using the `--build`, `--java-version`, `--dependencies`, and `--packaging` options. ```bash $ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip Using service at https://start.spring.io Content saved to 'sample-app.zip' ``` -------------------------------- ### Call RSocket service with RSocketRequester (Java) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Java example of a service that uses RSocketRequester.Builder to create a TCP connection and call an RSocket route. The builder is a prototype bean, so each injection point gets a new instance. ```java import reactor.core.publisher.Mono; import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.stereotype.Service; @Service public class MyService { private final RSocketRequester rsocketRequester; public MyService(RSocketRequester.Builder rsocketRequesterBuilder) { this.rsocketRequester = rsocketRequesterBuilder.tcp("example.org", 9898); } public Mono someRSocketCall(String name) { return this.rsocketRequester.route("user").data(name).retrieveMono(User.class); } } ``` -------------------------------- ### Use @AutoConfigureRestDocs with Mock MVC (Java) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Use @AutoConfigureRestDocs to enable Spring REST Docs in Mock MVC tests. It customizes the MockMvc bean and removes the need for the JUnit extension. This example documents the response of a GET request to /users. ```java import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(UserController.class) @AutoConfigureRestDocs class MyUserDocumentationTests { @Autowired private MockMvc mvc; @Test void listUsers() throws Exception { this.mvc.perform(get("/users").accept(MediaType.TEXT_PLAIN)) .andExpect(status().isOk()) .andDo(document("list-users")); } } ``` -------------------------------- ### Run mvn dependency:tree (initial) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows the project dependencies before adding spring-boot-starter-web. The output only lists the project itself, indicating no dependencies yet. ```bash $ mvn dependency:tree [INFO] com.example:myproject:jar:0.0.1-SNAPSHOT ``` -------------------------------- ### Spring Boot startup failure message for port 8080 in use Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example error message when the embedded servlet container fails to start because port 8080 is already in use. The message suggests identifying and stopping the process or configuring another port. ```text *************************** APPLICATION FAILED TO START *************************** Description: Embedded servlet container failed to start. Port 8080 was already in use. Action: Identify and stop the process that is listening on port 8080 or configure this application to listen on another port. ``` -------------------------------- ### Repackage implementation example (Java) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows a typical repackage implementation using Repackager and Libraries. It sets backupSource to false and repackages with a callback that provides libraries with COMPILE scope. ```Java 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 = ... 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 ... } } ``` -------------------------------- ### Kotlin example for @DataElasticsearchTest Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Typical setup for testing Elasticsearch applications with @DataElasticsearchTest in Kotlin. It configures ElasticsearchRestTemplate, scans @Document classes, and configures Spring Data Elasticsearch repositories. Regular @Component and @ConfigurationProperties beans are not scanned unless @EnableConfigurationProperties is used. ```kotlin import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest @DataElasticsearchTest class MyDataElasticsearchTests(@Autowired val repository: SomeRepository) { // ... } ``` -------------------------------- ### Create single instance environment with eb create -s Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Use this CLI command to create a single instance environment, which avoids the cost of a load balancer. ```bash eb create -s ``` -------------------------------- ### Java example for @DataElasticsearchTest Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Typical setup for testing Elasticsearch applications with @DataElasticsearchTest in Java. It configures ElasticsearchRestTemplate, scans @Document classes, and configures Spring Data Elasticsearch repositories. Regular @Component and @ConfigurationProperties beans are not scanned unless @EnableConfigurationProperties is used. ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest; @DataElasticsearchTest class MyDataElasticsearchTests { @Autowired private SomeRepository repository; // ... } ``` -------------------------------- ### Auto-configured Spring REST Docs test with Mock MVC (Kotlin) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example of a test class using @WebMvcTest and @AutoConfigureRestDocs to generate REST Docs snippets for a Mock MVC endpoint. The test performs a GET request to /users and documents it with the name 'list-users'. ```Kotlin import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.http.MediaType import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import org.springframework.test.web.servlet.result.MockMvcResultMatchers @WebMvcTest(UserController::class) @AutoConfigureRestDocs class MyUserDocumentationTests(@Autowired val mvc: MockMvc) { @Test fun listUsers() { mvc.perform(MockMvcRequestBuilders.get("/users").accept(MediaType.TEXT_PLAIN)) .andExpect(MockMvcResultMatchers.status().isOk) .andDo(MockMvcRestDocumentation.document("list-users")) } } ``` -------------------------------- ### Kotlin example for @DataCouchbaseTest Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Typical setup for testing Couchbase applications with @DataCouchbaseTest in Kotlin. It configures CouchbaseTemplate or ReactiveCouchbaseTemplate, scans @Document classes, and configures Spring Data Couchbase repositories. Regular @Component and @ConfigurationProperties beans are not scanned unless @EnableConfigurationProperties is used. ```kotlin import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest @DataCouchbaseTest class MyDataCouchbaseTests(@Autowired val repository: SomeRepository) { // ... } ``` -------------------------------- ### Java example for @DataCouchbaseTest Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Typical setup for testing Couchbase applications with @DataCouchbaseTest in Java. It configures CouchbaseTemplate or ReactiveCouchbaseTemplate, scans @Document classes, and configures Spring Data Couchbase repositories. Regular @Component and @ConfigurationProperties beans are not scanned unless @EnableConfigurationProperties is used. ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest; @DataCouchbaseTest class MyDataCouchbaseTests { @Autowired private SomeRepository repository; // ... } ``` -------------------------------- ### Deploying a WAR to WebLogic - Java servlet initializer Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Java example of a Spring Boot application class that directly implements WebApplicationInitializer, as required for WebLogic deployment. ```java 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 { } ``` -------------------------------- ### Share builder customizations between SpringBootServletInitializer and main method (Java) Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle This Java example shows how to share customizations of the SpringApplicationBuilder between the SpringBootServletInitializer callback and the main method. The configure method calls a customizerBuilder method, which should also be used in the main method to ensure consistent behavior whether starting as a war or as an executable application. ```java 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); } ``` -------------------------------- ### Install a CLI extension with spring install Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Installs a CLI extension using artifact coordinates in the format `group:artifact:version`. Dependencies are also installed. ```bash $ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE ``` -------------------------------- ### Install Spring Boot CLI with Scoop Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Installs Spring Boot CLI on Windows using Scoop. The 'spring' command is installed to ~/scoop/apps/springboot/current/bin. ```powershell > scoop bucket add extras > scoop install springboot ``` -------------------------------- ### Install Spring Boot CLI with Homebrew Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Installs Spring Boot CLI on macOS using Homebrew. The 'spring' command is installed to /usr/local/bin. ```bash $ brew tap spring-io/tap $ brew install spring-boot ``` -------------------------------- ### Remote devtools client startup output Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example output shown when the remote client application is running. It displays the Spring Boot banner and version information. ```text . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \ \\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) ) ' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / / =========|_|==============|___/===================================/_/_/_/ :: Spring Boot Remote :: (v2.7.18) ``` -------------------------------- ### Install Spring Boot CLI with MacPorts Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Installs Spring Boot CLI on macOS using MacPorts. ```bash $ sudo port install spring-boot-cli ``` -------------------------------- ### Typical project layout for Spring Boot application Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows a recommended directory structure with a root package containing the main application class and subpackages for customer and order domains. ```text com +- example +- myapplication +- MyApplication.java | +- customer | +- Customer.java | +- CustomerController.java | +- CustomerService.java | +- CustomerRepository.java | +- order +- Order.java +- OrderController.java +- OrderService.java +- OrderRepository.java ``` -------------------------------- ### Enable systemd service on boot Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Command to enable the myapp.service unit to start automatically on system boot. Run man systemctl for more details. ```bash $ systemctl enable myapp.service ``` -------------------------------- ### Manual metadata hints for my.contexts.keys Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Adds JSON hints to the manual metadata of a module to offer content assistance for the keys 'sample1' and 'sample2'. The magic values in this example are 'sample1' and 'sample2'. ```json {"hints": [ { "name": "my.contexts.keys", "values": [ { "value": "sample1" }, { "value": "sample2" } ] } ]} ``` -------------------------------- ### Project structure with trigger file Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example directory structure showing where the trigger file .reloadtrigger should be placed in the classpath. ```text src +- main +- resources +- .reloadtrigger ``` -------------------------------- ### List installed Spring Boot CLI versions with SDKMAN! Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Shows the output of 'sdk ls springboot', listing available versions and indicating the currently in-use dev instance. ```bash $ sdk ls springboot ================================================================================ Available Springboot Versions ================================================================================ > + dev * 2.7.18 ================================================================================ + - local version * - installed > - currently in use ================================================================================ ``` -------------------------------- ### JMX beans DSL example Source: https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle Example of using the beans DSL for JMX configuration in Spring Boot CLI. ```groovy beans { service(SharedService) { message = "Hello World" } } ```