### Install Spring Boot CLI on Windows with Scoop
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Install the Spring Boot CLI on Windows using Scoop. This process involves adding the 'extras' bucket to Scoop's configuration, then executing `scoop install springboot`. Scoop installs the `spring` executable to `~/scoop/apps/springboot/current/bin`.
```Shell
> scoop bucket add extras
> scoop install springboot
```
--------------------------------
### Install and Verify Spring Boot CLI with SDKMAN!
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This snippet provides the command-line instructions to install the Spring Boot CLI using SDKMAN! (The Software Development Kit Manager) and then verify the installed version. SDKMAN! simplifies the management of multiple SDK versions.
```Shell
$ sdk install springboot
$ spring --version
Spring Boot v{spring-boot-version}
```
--------------------------------
### Initialize and Start PostgreSQL Server
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc
Commands to initialize a new PostgreSQL data directory with UTF-8 encoding and start the PostgreSQL server, logging output to a specified file. This is the first step to get the database running.
```bash
$ initdb /usr/local/var/postgres -E utf8
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
```
--------------------------------
### Install Spring Boot CLI Dev Instance with SDKMAN!
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Use SDKMAN! to install a local 'dev' instance of the Spring Boot CLI, pointing to a custom build location. This ensures the CLI is always up-to-date with your latest Spring Boot rebuilds. The snippet also includes a command to verify the installed version.
```Shell
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-{spring-boot-version}-bin/spring-{spring-boot-version}/
$ sdk default springboot dev
$ spring --version
Spring CLI v{spring-boot-version}
```
--------------------------------
### Verify Spring Boot CLI Installation
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt
This command confirms that the Spring Boot CLI has been successfully installed and is accessible from the command line. Running it will display the installed CLI version, indicating a successful setup.
```Bash
spring --version
```
--------------------------------
### List Spring Boot CLI Versions with SDKMAN!
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Execute the `sdk ls springboot` command to display all available and installed Spring Boot CLI versions managed by SDKMAN!. This output helps identify the currently active and local 'dev' instances.
```Shell
$ sdk ls springboot
================================================================================
Available Springboot Versions
================================================================================
> + dev
* {spring-boot-version}
================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
```
--------------------------------
### Run Spring Boot Application using Maven
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This command demonstrates how to start a Spring Boot application using the Maven `spring-boot:run` goal. This goal is provided by the `spring-boot-starter-parent` POM and simplifies the execution of Spring Boot applications directly from the command line.
```Shell
$ mvn spring-boot:run
```
--------------------------------
### Basic Spring Boot Maven POM Configuration
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This XML snippet illustrates a typical `pom.xml` file for a Spring Boot project using Maven. It demonstrates how to inherit default configurations from the `spring-boot-starter-parent` and define basic project metadata like `groupId`, `artifactId`, and `version`. This setup is fundamental for most Maven-based Spring Boot applications.
```XML
4.0.0
com.example
myproject
0.0.1-SNAPSHOT
```
--------------------------------
### Check Maven Version
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Confirm the installed Apache Maven version, which is used for building Spring Boot projects. This command provides details about the Maven installation and the Java version it uses.
```Shell
$ mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T14:33:14-04:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_102, vendor: Oracle Corporation
```
--------------------------------
### Check Java Version
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Verify the installed Java Development Kit (JDK) version to ensure compatibility with Spring Boot projects. This command displays the Java runtime environment and virtual machine details.
```Shell
$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
```
--------------------------------
### Install Spring Boot CLI on macOS with Homebrew
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Install the Spring Boot CLI on macOS using Homebrew. This involves tapping the `pivotal/tap` repository to access the Spring Boot formula, followed by the `brew install springboot` command. Homebrew automatically places the `spring` executable in `/usr/local/bin`.
```Shell
$ brew tap pivotal/tap
$ brew install springboot
```
--------------------------------
### Verify Java Development Kit Version
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Before installing Spring Boot, it's essential to confirm that Java Development Kit (JDK) version 1.8 or higher is installed on your system. Use this command in your terminal to check the currently installed Java version.
```Shell
$ java -version
```
--------------------------------
### Enable Spring Boot CLI Bash Completion (SDKMAN!)
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Manually enable BASH command-line completion for the Spring Boot CLI when it's installed via SDKMAN!. Sourcing the `spring` script from the SDKMAN! candidates directory allows for tab completion of CLI commands like `grab`, `help`, `jar`, `run`, `test`, and `version`.
```Shell
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
$ spring
grab help jar run test version
```
--------------------------------
### Run Spring Boot Executable Jar
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Once the executable JAR is built, it can be run directly using the `java -jar` command. This command starts the Spring Boot application, displaying its characteristic ASCII art banner and log output, indicating that the application is running.
```Shell
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v{spring-boot-version})
....... . . .
....... . . . (log output here)
....... . . .
........ Started Example in 2.536 seconds (JVM running for 2.864)
```
--------------------------------
### Spring Boot systemd Service File Example
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
Example of a systemd service unit file (`myapp.service`) for a Spring Boot application installed at `/var/myapp`. This file defines the service's description, user, execution command, and target for automatic startup. Remember to modify `Description`, `User`, and `ExecStart` fields for your specific application.
```Shell
[Unit]
Description=myapp
After=syslog.target
[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
```
--------------------------------
### Build Spring Boot Project with Maven
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Run the Maven `package` goal to build the Spring Boot project. This command compiles the source code, runs tests, and packages the compiled code into a distributable format, typically a JAR file.
```Shell
mvn package
```
--------------------------------
### Create Maven POM for Spring Boot Project
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Define the `pom.xml` file for a new Spring Boot application. This Maven project object model includes the `spring-boot-starter-parent` for dependency management and optional repository configurations for non-release versions.
```XML
4.0.0
com.example
myproject
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
{spring-boot-version}
ifeval::["{spring-boot-repo}" != "release"]
spring-snapshots
https://repo.spring.io/snapshot
true
spring-milestones
https://repo.spring.io/milestone
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
endif::[]
```
--------------------------------
### Run Spring Boot Groovy Application with CLI
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Execute the `app.groovy` Spring Boot application using the Spring CLI's `run` command. This command automatically handles dependency resolution and starts an embedded web server, making the application accessible via `http://localhost:8080`.
```Shell
$ spring run app.groovy
```
--------------------------------
### Add Spring Boot Web Starter Dependency to pom.xml
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This XML snippet demonstrates how to add the `spring-boot-starter-web` dependency to a Maven `pom.xml` file. This starter brings in essential web-related dependencies like Tomcat and Spring MVC, enabling the development of web applications.
```XML
org.springframework.boot
spring-boot-starter-web
```
--------------------------------
### View Maven Dependency Tree
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Display the full dependency tree of the Maven project. This command helps in understanding and debugging classpath issues by showing all direct and transitive dependencies.
```Shell
$ mvn dependency:tree
```
--------------------------------
### Verify Spring Boot Application Output in Browser
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This snippet shows the expected output when accessing the running Spring Boot application at `http://localhost:8080` in a web browser. It confirms that the `home()` method mapped to the root path successfully returned 'Hello World!'.
```Text
Hello World!
```
--------------------------------
### Install Spring Boot CLI on macOS with MacPorts
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Install the Spring Boot CLI on macOS using MacPorts. The `sudo port install spring-boot-cli` command is used, requiring superuser privileges to complete the installation.
```Shell
$ sudo port install spring-boot-cli
```
--------------------------------
### Create a Basic Spring Boot 'Hello World' Application
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This Java code defines a simple Spring Boot application. It uses `@RestController` to mark the class as a web controller, `@RequestMapping("/")` to map the root path to the `home()` method returning 'Hello World!', and `@EnableAutoConfiguration` for automatic Spring configuration. The `main` method bootstraps the application using `SpringApplication.run()`.
```Java
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) throws Exception {
SpringApplication.run(Example.class, args);
}
}
```
--------------------------------
### Create a Simple Spring Boot Groovy Web Application
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Define a basic Spring Boot web application in Groovy. This `app.groovy` file uses `@RestController` and `@RequestMapping` to create a simple endpoint that returns 'Hello World!' when accessed at the root path (`/`).
```Groovy
@RestController
class ThisWillActuallyRun {
@RequestMapping("/")
String home() {
"Hello World!"
}
}
```
--------------------------------
### Start WildFly with Custom Configuration
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc
Shell command to start the WildFly application server using the custom standalone-boot-demo.xml configuration file. This ensures that WildFly runs with the previously defined DataSource and JMS settings.
```bash
$JBOSS_HOME/bin/standalone.sh -c standalone-boot-demo.xml
```
--------------------------------
### Maven POM Configuration for Spring Boot Web Application
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
This Maven `pom.xml` snippet illustrates the essential configuration for a Spring Boot web application. It includes inheriting from `spring-boot-starter-parent`, adding the `spring-boot-starter-web` dependency, and configuring the `spring-boot-maven-plugin` to create an executable JAR. It also shows how to declare Spring snapshot and milestone repositories and plugin repositories.
```XML
org.springframework.boot
spring-boot-starter-parent
{spring-boot-version}
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-maven-plugin
spring-snapshots
https://repo.spring.io/snapshot
true
spring-milestones
https://repo.spring.io/milestone
spring-snapshots
https://repo.spring.io/snapshot
spring-milestones
https://repo.spring.io/milestone
```
--------------------------------
### Start Spring Boot init.d Service
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
This command starts a Spring Boot application that has been installed as an `init.d` service on a Debian-based system. Replace `myapp` with the actual service name.
```shell
$ service myapp start
```
--------------------------------
### Share Spring Boot Application Customizations for WAR and Executable JAR
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This example illustrates how to share common application builder customizations when a Spring Boot application is intended to be deployed as both a WAR and an executable JAR. A shared `private static` method encapsulates the configuration, ensuring consistency whether the application is started via `SpringBootServletInitializer` or the `main` method.
```Java
@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);
}
}
```
--------------------------------
### Inspect Spring Boot Executable Jar Contents
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
To view the contents of the generated executable JAR file, you can use the standard `jar tvf` command. This is useful for verifying that all necessary classes and dependencies have been correctly packaged within the 'fat jar'.
```Shell
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
```
--------------------------------
### Expected Output of Spring Boot Groovy Application
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
The expected output displayed in a web browser when accessing the `Hello World!` Spring Boot application running on `http://localhost:8080`. This confirms the application is running correctly and serving content.
```Shell
Hello World!
```
--------------------------------
### JavaScript Initial Game Startup Call
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html
The final execution line that initiates the entire game application. This call to `Game.initialize()` triggers the setup of the canvas, event listeners, and the establishment of the WebSocket connection, effectively starting the multiplayer Snake game.
```JavaScript
Game.initialize();
```
--------------------------------
### Add Spring Boot Maven Plugin to pom.xml
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
To enable the creation of executable JARs, the `spring-boot-maven-plugin` must be added to the `build` section of your `pom.xml`. This plugin handles the repackaging of the application into a 'fat jar' that includes all dependencies. If not using the `spring-boot-starter-parent` POM, the `repackage` goal needs to be explicitly bound.
```XML
org.springframework.boot
spring-boot-maven-plugin
```
--------------------------------
### Build Spring Boot Executable Jar with Maven
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
After configuring the `spring-boot-maven-plugin`, run `mvn package` from the command line to build the project. This command compiles the code, runs tests, and then uses the Spring Boot plugin to create the executable JAR, typically located in the `target` directory.
```Shell
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] .... ..
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject ---
[INFO] Building jar: /Users/developer/example/spring-boot-example/target/myproject-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:{spring-boot-version}:repackage (default) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
```
--------------------------------
### Add Spring Boot Web Starter Dependency (Maven)
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
To enable logging in a Spring Boot web application, including Logback, the `spring-boot-starter-web` Maven dependency can be added. This starter transitively includes `spring-boot-starter-logging`, simplifying the setup for common logging requirements.
```XML
org.springframework.boot
spring-boot-starter-web
```
--------------------------------
### Install Spring Boot Application as init.d Service
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
This command creates a symbolic link from the Spring Boot executable JAR to `/etc/init.d`, allowing the application to be managed as a System V `init.d` service. This enables standard service commands like `start`, `stop`, `restart`, and `status`.
```shell
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
```
--------------------------------
### Enable Automatic Startup for init.d Service
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
This command configures a Spring Boot application, installed as an `init.d` service, to start automatically at boot time on Debian-based systems. The `` argument specifies the startup order.
```shell
$ update-rc.d myapp defaults
```
--------------------------------
### JavaScript Game Entry Point Initialization
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html
This single line of code serves as the entry point for the entire game application. It calls the `Game.initialize()` function, which in turn sets up the canvas, event listeners, and initiates the WebSocket connection, effectively starting the game.
```JavaScript
Game.initialize();
```
--------------------------------
### Spring Boot Ant `exejar` Task Examples
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc
Examples demonstrating the usage of the `spring-boot:exejar` Ant task to create executable JARs, showing both explicit `start-class` specification and automatic detection.
```XML
```
```XML
```
--------------------------------
### Example HTTP Response for Flyway Migrations
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/flyway.adoc
Illustrates a typical JSON response received from the `/actuator/flyway` endpoint, detailing the status and history of database migrations.
```HTTP
HTTP/1.1 200 OK
Content-Type: application/json
{
"contexts": {
"application": {
"flyway": {
"migrations": [
{
"checksum": 1234567890,
"description": "initial_schema",
"installedRank": 1,
"script": "V1__initial_schema.sql",
"state": "SUCCESS",
"type": "SQL",
"version": "1"
},
{
"checksum": 9876543210,
"description": "add_users_table",
"installedRank": 2,
"script": "V2__add_users_table.sql",
"state": "SUCCESS",
"type": "SQL",
"version": "2"
}
]
}
}
}
}
```
--------------------------------
### Switch Spring Boot Redis Client from Lettuce to Jedis
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
These examples show how to configure your build system (Maven or Gradle) to replace the default Lettuce Redis client with Jedis in a Spring Boot application.
```XML
org.springframework.boot
spring-boot-starter-data-redis
io.lettuce
lettuce-core
redis.clients
jedis
```
```Groovy
configurations {
compile.exclude module: "lettuce"
}
dependencies {
compile("redis.clients:jedis")
// ...
}
```
--------------------------------
### Example Spring Boot Configuration Metadata JSON Format
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc
Illustrates the structure of META-INF/spring-configuration-metadata.json files, showing 'groups', 'properties', and 'hints' sections with example entries for server and JPA properties.
```json
{"groups": [
{
"name": "server",
"type": "org.springframework.boot.autoconfigure.web.ServerProperties",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
},
{
"name": "spring.jpa.hibernate",
"type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate",
"sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties",
"sourceMethod": "getHibernate()"
}
...
],"properties": [
{
"name": "server.port",
"type": "java.lang.Integer",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
},
{
"name": "server.address",
"type": "java.net.InetAddress",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
},
{
"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."
}
]
}
]}
```
--------------------------------
### Using @SpringBootApplication for Standard Spring Boot Setup
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
This example illustrates the use of the @SpringBootApplication annotation, which conveniently combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. It's the standard way to bootstrap a Spring Boot application, enabling auto-configuration, component scanning, and allowing additional bean definitions.
```java
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);
}
}
```
--------------------------------
### JavaScript Initial Game Startup Call
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html
The final line of the script that initiates the entire game. This call to 'Game.initialize()' sets up the canvas, attaches event listeners, and establishes the WebSocket connection, effectively starting the multiplayer Snake game.
```JavaScript
Game.initialize();
```
--------------------------------
### Configure MANIFEST.MF for Spring Boot Executable WAR
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-executable-jar-format.adoc
Example of a `META-INF/MANIFEST.MF` file for an executable WAR, specifying `WarLauncher` as the `Main-Class` and the application's main class as `Start-Class`. This setup is crucial for deploying Spring Boot applications as WAR files.
```Manifest
Main-Class: org.springframework.boot.loader.WarLauncher
Start-Class: com.mycompany.project.MyApplication
```
--------------------------------
### Example Spring Boot Repackage Implementation in Java
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc
This example demonstrates how to use the `Repackager` class to create a self-contained executable archive. It shows setting `backupSource` to false and providing a `Libraries` implementation to handle nested dependencies, typically specific to the build system.
```java
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));
}
});
```
--------------------------------
### Example Spring Boot Application Properties Configuration
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc
Demonstrates how server.port and server.address properties are specified in an application.properties file, corresponding to entries in the configuration metadata.
```properties
server.port=9090
server.address=127.0.0.1
```
--------------------------------
### Setup WildFly PostgreSQL JDBC Driver Module
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc
Shell commands to create the necessary directory structure within WildFly's modules, download the PostgreSQL JDBC driver JAR, and move it into the module directory. This prepares WildFly to recognize the PostgreSQL driver for database connections.
```bash
$ cd $JBOSS_HOME
mkdir -p modules/org/postgresql/main
wget http://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar
mv postgresql-9.3-1102.jdbc41.jar modules/org/postgresql/main
```
--------------------------------
### Example Prometheus Metrics HTTP Response
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/prometheus.adoc
An example of the metrics data returned by the `/actuator/prometheus` endpoint, formatted for Prometheus scraping.
```text
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{area="heap",id="PS Eden Space"} 1.073741824E9
jvm_memory_used_bytes{area="nonheap",id="Code Cache"} 2.097152E7
# HELP process_cpu_usage The "recent cpu usage" for the Java Virtual Machine process.
# TYPE process_cpu_usage gauge
process_cpu_usage 0.01
```
--------------------------------
### Add Spring Boot Properties Migrator Dependency
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc
Include the `spring-boot-properties-migrator` Maven dependency in a project's `pom.xml`. This runtime-scoped dependency provides diagnostic capabilities at startup and can temporarily migrate renamed or removed properties, aiding in the upgrade process from earlier Spring Boot versions.
```XML
org.springframework.boot
spring-boot-properties-migrator
runtime
```
--------------------------------
### Example JSON Output from Custom Spring Boot InfoContributor
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc
Illustrates the expected JSON response from the `info` endpoint after registering a custom `InfoContributor`. This snippet shows how the custom "example" entry, with its nested "key" and "value", appears in the output.
```json
{
"example": {
"key" : "value"
}
}
```
--------------------------------
### Example HTTP Response for Spring Boot Configuration Properties
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/configprops.adoc
Illustrates the typical JSON response structure returned by the `/actuator/configprops` endpoint, detailing the application's `@ConfigurationProperties` beans.
```HTTP
HTTP/1.1 200 OK
Content-Type: application/json
{
"contexts": {
"application": {
"beans": {
"spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties": {
"prefix": "spring.datasource",
"properties": {
"url": "jdbc:h2:mem:testdb",
"username": "sa",
"password": ""
}
},
"server-org.springframework.boot.autoconfigure.web.ServerProperties": {
"prefix": "server",
"properties": {
"port": 8080,
"servlet": {
"context-path": "/"
}
}
}
}
}
}
}
```
--------------------------------
### Check Java JDK Version for Spring Boot CLI
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt
This command verifies that a compatible Java Development Kit (JDK) version (v1.8 or above) is installed and accessible on the system's PATH. The Spring Boot CLI requires Java to run correctly.
```Bash
java -version
```
--------------------------------
### Tomcat HTTP/2 ALPN Configuration Error Log
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This log entry shows a non-fatal error encountered when starting Tomcat 9.0.x on JDK 8 without native ALPN support for HTTP/2. The application still starts with HTTP/1.1 SSL support despite this warning.
```Console
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
```
--------------------------------
### Applying MeterFilter for Metric Customization
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc
Use the `io.micrometer.core.instrument.config.MeterFilter` interface to apply specific customizations to `Meter` instances. This example demonstrates how to rename a tag (`mytag.region` to `mytag.area`) for meter IDs starting with `com.example`.
```java
include::{code-examples}/actuate/metrics/MetricsFilterBeanExample.java[tag=configuration]
```
--------------------------------
### Run Spring Boot Quartz Application with Maven
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-quartz/README.adoc
This command builds and runs the Spring Boot application directly from the command line using Maven's `spring-boot:run` goal. After execution, the console will display 'Hello World!' messages from `SampleJob` every 2 seconds, demonstrating the Quartz scheduler in action.
```Shell
$ mvn spring-boot:run
```
--------------------------------
### Retrieve Partial Log File using cURL with Range Header
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/logfile.adoc
Illustrates how to retrieve a specific portion of the log file by sending a GET request to `/actuator/logfile` with a `Range` header. This example fetches the first 1024 bytes.
```curl
curl -H "Range: bytes=0-1023" http://localhost:8080/actuator/logfile
```
```HTTP
HTTP/1.1 206 Partial Content
Content-Type: text/plain;charset=UTF-8
Content-Range: bytes 0-1023/20480
2023-10-27 10:00:00.000 INFO [main] com.example.Application - Starting Application
... (first 1024 bytes of log content)
```
--------------------------------
### Displaying Detailed Help for Spring CLI Run Command
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc
This snippet demonstrates how to get detailed help for a specific Spring CLI command, in this case, `run`. It outlines the command's usage, available options, and their descriptions, such as `--autoconfigure`, `--classpath`, and `--watch`, aiding in proper command usage.
```Shell
$ spring help run
spring run - Run a spring groovy script
usage: spring run [options] [--] [args]
Option Description
------ -----------
--autoconfigure [Boolean] Add autoconfigure compiler
transformations (default: true)
--classpath, -cp Additional classpath entries
-e, --edit Open the file with the default system
editor
--no-guess-dependencies Do not attempt to guess dependencies
--no-guess-imports Do not attempt to guess imports
-q, --quiet Quiet logging
-v, --verbose Verbose logging of dependency
resolution
--watch Watch the specified file for changes
```
--------------------------------
### Configure Flyway Profile-Specific Migration Locations
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This example demonstrates how to configure Flyway migration locations specific to a Spring profile (e.g., 'dev'). When the 'dev' profile is active, Flyway will search for scripts in both the default location and the profile-specific directory.
```Properties
spring.flyway.locations=classpath:/db/migration,classpath:/dev/db/migration
```
--------------------------------
### Initialize New Spring Boot Project with CLI
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc
Demonstrates using the `spring init` command to create a new Spring Boot project directly from the command line, leveraging the Spring Initializr service. This allows for quick project setup with specified dependencies.
```Shell
$ spring init --dependencies=web,data-jpa my-project
Using service at https://start.spring.io
```
--------------------------------
### Disabling Specific Meters via Properties
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc
Spring Boot allows limited per-meter customization using properties. This example demonstrates how to disable any meters whose ID starts with `example.remote` by setting the `management.metrics.enable` property to `false` for that prefix.
```properties
management.metrics.enable.example.remote=false
```
--------------------------------
### View Cloud Foundry Applications
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc
Demonstrates how to use the `cf apps` command-line tool to list all applications deployed to Cloud Foundry, showing their state, resource allocation, and public URLs.
```bash
$ cf apps
Getting applications in ...
OK
name requested state instances memory disk urls
...
acloudyspringtime started 1/1 512M 1G acloudyspringtime.cfapps.io
...
```
--------------------------------
### Configure RestTemplate with Proxy and Exclusion
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This example demonstrates how to customize a `RestTemplate` to route requests through a proxy using `RestTemplateCustomizer` and `RestTemplateBuilder`. It specifically configures `HttpComponentsClientRequestFactory` with an `HttpClient` that uses a proxy for all hosts except `192.168.0.5`, showcasing advanced proxy routing.
```Java
package com.example.web.client;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Component
public class ProxyCustomizer implements RestTemplateCustomizer {
@Override
public void customize(RestTemplate restTemplate) {
HttpHost proxy = new HttpHost("proxy.example.com", 8080); // Example proxy host and port
HttpClient httpClient = HttpClientBuilder.create()
.setProxy(proxy)
.setRoutePlanner((target, request, context) -> {
// Exclude specific hosts from proxying
if (target.getHostName().equals("192.168.0.5")) {
return new HttpRoute(target); // Direct connection
}
return new HttpRoute(target, null, proxy, false); // Route through proxy
})
.build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
}
```
--------------------------------
### Initialize Script and Resolve Application Home Directory (Shell)
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/resources/unixStartScript.txt
This section initializes the script by setting up basic variables and robustly determines the `APP_HOME` directory. It handles symbolic links to ensure the script can locate its base directory correctly, regardless of how it's invoked.
```sh
#!/usr/bin/env sh
##############################################################################
##
## ${applicationName} start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: \$0 may be a link
PRG="\$0"
# Need this for relative symlinks.
while [ -h "\$PRG" ] ; do
ls=`ls -ld "\$PRG"`
link=`expr "\$ls" : '.*-> \(.*\)\$'`
if expr "\$link" : '/.*' > /dev/null; then
PRG="\$link"
else
PRG=`dirname "\$PRG"`"/\$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"\$PRG\"`/${appHomeRelativePath}" >/dev/null
APP_HOME="`pwd -P`"
cd "\$SAVED" >/dev/null
APP_NAME="${applicationName}"
APP_BASE_NAME=`basename "\$0"`
# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script.
DEFAULT_JVM_OPTS=${defaultJvmOpts}
```
--------------------------------
### Enable Multiple HTTP/HTTPS Connectors in Embedded Tomcat
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This Java code demonstrates how to add multiple `org.apache.catalina.connector.Connector` instances to a `TomcatServletWebServerFactory` bean in Spring Boot. It includes an example of configuring an SSL connector with a keystore and truststore for HTTPS communication on a specific port.
```Java
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createSslConnector());
return tomcat;
}
private Connector createSslConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
try {
File keystore = new ClassPathResource("keystore").getFile();
File truststore = new ClassPathResource("keystore").getFile();
connector.setScheme("https");
connector.setSecure(true);
connector.setPort(8443);
protocol.setSSLEnabled(true);
protocol.setKeystoreFile(keystore.getAbsolutePath());
protocol.setKeystorePass("changeit");
protocol.setTruststoreFile(truststore.getAbsolutePath());
protocol.setTruststorePass("changeit");
protocol.setKeyAlias("apitester");
return connector;
}
catch (IOException ex) {
throw new IllegalStateException("can't access keystore: [" + "keystore"
+ "] or truststore: [" + "keystore" + "]", ex);
}
}
```
--------------------------------
### Run Spring Boot Application with Redis Session Store
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-samples/spring-boot-sample-session-webflux/README.adoc
Instructions to run the sample application using Redis as the session store. This requires adding `org.springframework.session:spring-session-data-redis` and `spring-boot-starter-data-redis-reactive` dependencies and ensuring a Redis instance is properly configured (default settings expected on local box).
```Bash
$mvn spring-boot:run -Predis
```
--------------------------------
### Recommended Spring Boot Project Code Layout
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
This snippet illustrates a typical and recommended directory and package structure for a Spring Boot application. It emphasizes placing the main application class in a root package (e.g., com.example.myapplication) to define a base search package for component scanning and entity discovery, while organizing domain-specific classes into sub-packages.
```plaintext
com
+- example
+- myapplication
+- Application.java
|
+- customer
| +- Customer.java
| +- CustomerController.java
| +- CustomerService.java
| +- CustomerRepository.java
|
+- order
+- Order.java
+- OrderController.java
+- OrderService.java
+- OrderRepository.java
```
--------------------------------
### Enable Multiple Listeners in Embedded Undertow Server
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
This Java example demonstrates how to add multiple HTTP listeners to an embedded Undertow server in Spring Boot. It utilizes an `UndertowBuilderCustomizer` within an `UndertowServletWebServerFactory` bean to configure additional listeners, such as one on port 8080.
```Java
@Bean
public UndertowServletWebServerFactory servletWebServerFactory() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override
public void customize(Builder builder) {
builder.addHttpListener(8080, "0.0.0.0");
}
});
return factory;
}
```
--------------------------------
### Enable Shell Auto-Completion for Spring Boot CLI
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt
These commands create symbolic links to enable shell auto-completion for the Spring Boot CLI. This enhances the command-line experience by providing suggestions for Spring Boot CLI commands in Bash and Zsh environments.
```Bash
ln -s ./shell-completion/bash/spring /etc/bash_completion.d/spring
```
```Zsh
ln -s ./shell-completion/zsh/_spring /usr/local/share/zsh/site-functions/_spring
```
--------------------------------
### Define Utility Functions for Script Output and Error Handling (Shell)
Source: https://github.com/yuanmabiji/spring-boot-2.1.0.release/blob/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/resources/unixStartScript.txt
This snippet defines two helper functions: `warn` for printing non-fatal warning messages to standard output, and `die` for printing error messages to standard output and then exiting the script with a non-zero status code. These functions standardize error reporting.
```sh
warn ( ) {
echo "\$*"
}
die ( ) {
echo
echo "\$*"
echo
exit 1
}
```