@ -1159,9 +1159,12 @@ If you want to display the full git information (that is, the full content of `g
To disable the git commit information from the `info` endpoint completely, set the configprop:management.info.git.enabled[] property to `false`, as follows:
To disable the git commit information from the `info` endpoint completely, set the configprop:management.info.git.enabled[] property to `false`, as follows:
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from https://grails.org/[Grails]), and you can embed bean definitions in your Groovy application scripts by using the same format.
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from https://grails.org/[Grails]), and you can embed bean definitions in your Groovy application scripts by using the same format.
This is sometimes a good way to include external features like middleware declarations, as shown in the following example:
This is sometimes a good way to include external features like middleware declarations, as shown in the following example:
To compile and run the application, type the following command:
To compile and run the application, type the following command:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring run hello.groovy
$ spring run hello.groovy
----
----
To pass command-line arguments to the application, use `--` to separate the commands from the "`spring`" command arguments, as shown in the following example:
To pass command-line arguments to the application, use `--` to separate the commands from the "`spring`" command arguments, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring run hello.groovy -- --server.port=9000
$ spring run hello.groovy -- --server.port=9000
----
----
To set JVM command line arguments, you can use the `JAVA_OPTS` environment variable, as shown in the following example:
To set JVM command line arguments, you can use the `JAVA_OPTS` environment variable, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
----
----
@ -201,7 +201,7 @@ However, to ensure consistent ordering of the dependency management, you can use
You can use "`shell globbing`" with all commands that accept file input.
You can use "`shell globbing`" with all commands that accept file input.
Doing so lets you use multiple files from a single directory, as shown in the following example:
Doing so lets you use multiple files from a single directory, as shown in the following example:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring run *.groovy
$ spring run *.groovy
----
----
@ -212,7 +212,7 @@ Doing so lets you use multiple files from a single directory, as shown in the fo
=== Packaging Your Application
=== Packaging Your Application
You can use the `jar` command to package your application into a self-contained executable jar file, as shown in the following example:
You can use the `jar` command to package your application into a self-contained executable jar file, as shown in the following example:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring jar my-app.jar *.groovy
$ spring jar my-app.jar *.groovy
----
----
@ -243,7 +243,7 @@ Type `spring help jar` on the command line for more information.
=== Initialize a New Project
=== Initialize a New Project
The `init` command lets you create a new project by using https://start.spring.io without leaving the shell, as shown in the following example:
The `init` command lets you create a new project by using https://start.spring.io without leaving the shell, as shown in the following example:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring init --dependencies=web,data-jpa my-project
$ spring init --dependencies=web,data-jpa my-project
Using service at https://start.spring.io
Using service at https://start.spring.io
@ -253,7 +253,7 @@ The `init` command lets you create a new project by using https://start.spring.i
The preceding example creates a `my-project` directory with a Maven-based project that uses `spring-boot-starter-web` and `spring-boot-starter-data-jpa`.
The preceding example creates a `my-project` directory with a Maven-based project that uses `spring-boot-starter-web` and `spring-boot-starter-data-jpa`.
You can list the capabilities of the service by using the `--list` flag, as shown in the following example:
You can list the capabilities of the service by using the `--list` flag, as shown in the following example:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring init --list
$ spring init --list
=======================================
=======================================
@ -282,7 +282,7 @@ The `init` command supports many options.
See the `help` output for more details.
See the `help` output for more details.
For instance, the following command creates a Gradle project that uses Java 8 and `war` packaging:
For instance, the following command creates a Gradle project that uses Java 8 and `war` packaging:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip
$ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip
Using service at https://start.spring.io
Using service at https://start.spring.io
@ -296,7 +296,7 @@ For instance, the following command creates a Gradle project that uses Java 8 an
Spring Boot includes command-line completion scripts for the BASH and zsh shells.
Spring Boot includes command-line completion scripts for the BASH and zsh shells.
If you do not use either of these shells (perhaps you are a Windows user), you can use the `shell` command to launch an integrated shell, as shown in the following example:
If you do not use either of these shells (perhaps you are a Windows user), you can use the `shell` command to launch an integrated shell, as shown in the following example:
@ -322,7 +322,7 @@ To exit the embedded shell, press `ctrl-c`.
You can add extensions to the CLI by using the `install` command.
You can add extensions to the CLI by using the `install` command.
The command takes one or more sets of artifact coordinates in the format `group:artifact:version`, as shown in the following example:
The command takes one or more sets of artifact coordinates in the format `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
----
----
@ -332,7 +332,7 @@ In addition to installing the artifacts identified by the coordinates you supply
To uninstall a dependency, use the `uninstall` command.
To uninstall a dependency, use the `uninstall` command.
As with the `install` command, it takes one or more sets of artifact coordinates in the format of `group:artifact:version`, as shown in the following example:
As with the `install` command, it takes one or more sets of artifact coordinates in the format of `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
----
----
@ -341,7 +341,7 @@ It uninstalls the artifacts identified by the coordinates you supply and their d
To uninstall all additional dependencies, you can use the `--all` option, as shown in the following example:
To uninstall all additional dependencies, you can use the `--all` option, as shown in the following example:
@ -27,7 +27,7 @@ Once you have built your application (by using, for example, `mvn clean package`
Be sure to have https://docs.cloudfoundry.org/cf-cli/getting-started.html#login[logged in with your `cf` command line client] before pushing an application.
Be sure to have https://docs.cloudfoundry.org/cf-cli/getting-started.html#login[logged in with your `cf` command line client] before pushing an application.
The following line shows using the `cf push` command to deploy an application:
The following line shows using the `cf push` command to deploy an application:
@ -68,7 +68,7 @@ Congratulations! The application is now live!
Once your application is live, you can verify the status of the deployed application by using the `cf apps` command, as shown in the following example:
Once your application is live, you can verify the status of the deployed application by using the `cf apps` command, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ cf apps
$ cf apps
Getting applications in ...
Getting applications in ...
@ -161,7 +161,7 @@ The `$PORT` environment variable is assigned to us by the Heroku PaaS.
This should be everything you need.
This should be everything you need.
The most common deployment workflow for Heroku deployments is to `git push` the code to production, as shown in the following example:
The most common deployment workflow for Heroku deployments is to `git push` the code to production, as shown in the following example:
[indent=0,subs="verbatim,quotes"]
[source,shell,indent=0,subs="verbatim,quotes"]
----
----
$ git push heroku main
$ git push heroku main
@ -308,7 +308,7 @@ Boxfuse leverages this information both for the images it produces as well as fo
Once you have created a https://console.boxfuse.com[Boxfuse account], connected it to your AWS account, installed the latest version of the Boxfuse Client, and ensured that the application has been built by Maven or Gradle (by using, for example, `mvn clean package`), you can deploy your Spring Boot application to AWS with a command similar to the following:
Once you have created a https://console.boxfuse.com[Boxfuse account], connected it to your AWS account, installed the latest version of the Boxfuse Client, and ensured that the application has been built by Maven or Gradle (by using, for example, `mvn clean package`), you can deploy your Spring Boot application to AWS with a command similar to the following:
@ -16,7 +16,7 @@ At runtime you shouldn't expect any differences.
Once you have unpacked the jar file, you can also get an extra boost to startup time by running the app with its "natural" main method instead of the `JarLauncher`. For example:
Once you have unpacked the jar file, you can also get an extra boost to startup time by running the app with its "natural" main method instead of the `JarLauncher`. For example:
@ -66,7 +66,7 @@ The script supports the following features:
Assuming that you have a Spring Boot application installed in `/var/myapp`, to install a Spring Boot application as an `init.d` service, create a symlink, as follows:
Assuming that you have a Spring Boot application installed in `/var/myapp`, to install a Spring Boot application as an `init.d` service, create a symlink, as follows:
@ -74,7 +74,7 @@ Assuming that you have a Spring Boot application installed in `/var/myapp`, to i
Once installed, you can start and stop the service in the usual way.
Once installed, you can start and stop the service in the usual way.
For example, on a Debian-based system, you could start it with the following command:
For example, on a Debian-based system, you could start it with the following command:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ service myapp start
$ service myapp start
----
----
@ -84,7 +84,7 @@ TIP: If your application fails to start, check the log file written to `/var/log
You can also flag the application to start automatically by using your standard operating system tools.
You can also flag the application to start automatically by using your standard operating system tools.
For example, on Debian, you could use the following command:
For example, on Debian, you could use the following command:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ update-rc.d myapp defaults <priority>
$ update-rc.d myapp defaults <priority>
----
----
@ -101,7 +101,7 @@ When the environment variable is not set, the user who owns the jar file is used
You should never run a Spring Boot application as `root`, so `RUN_AS_USER` should never be root and your application's jar file should never be owned by root.
You should never run a Spring Boot application as `root`, so `RUN_AS_USER` should never be root and your application's jar file should never be owned by root.
Instead, create a specific user to run your application and set the `RUN_AS_USER` environment variable or use `chown` to make it the owner of the jar file, as shown in the following example:
Instead, create a specific user to run your application and set the `RUN_AS_USER` environment variable or use `chown` to make it the owner of the jar file, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ chown bootapp:bootapp your-app.jar
$ chown bootapp:bootapp your-app.jar
----
----
@ -114,7 +114,7 @@ For example, you can set the account's shell to `/usr/sbin/nologin`.
You should also take steps to prevent the modification of your application's jar file.
You should also take steps to prevent the modification of your application's jar file.
Firstly, configure its permissions so that it cannot be written and can only be read or executed by its owner, as shown in the following example:
Firstly, configure its permissions so that it cannot be written and can only be read or executed by its owner, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ chmod 500 your-app.jar
$ chmod 500 your-app.jar
----
----
@ -123,7 +123,7 @@ Second, you should also take steps to limit the damage if your application or th
If an attacker does gain access, they could make the jar file writable and change its contents.
If an attacker does gain access, they could make the jar file writable and change its contents.
One way to protect against this is to make it immutable by using `chattr`, as shown in the following example:
One way to protect against this is to make it immutable by using `chattr`, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ sudo chattr +i your-app.jar
$ sudo chattr +i your-app.jar
----
----
@ -134,7 +134,7 @@ If root is used to control the application's service and you <<deployment#deploy
It should be secured accordingly.
It should be secured accordingly.
Use `chmod` so that the file can only be read by the owner and use `chown` to make root the owner, as shown in the following example:
Use `chmod` so that the file can only be read by the owner and use `chown` to make root the owner, as shown in the following example:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ chmod 400 your-app.conf
$ chmod 400 your-app.conf
$ sudo chown root:root your-app.conf
$ sudo chown root:root your-app.conf
@ -174,7 +174,7 @@ Consult the https://www.freedesktop.org/software/systemd/man/systemd.service.htm
To flag the application to start automatically on system boot, use the following command:
To flag the application to start automatically on system boot, use the following command:
@ -116,14 +116,14 @@ If you do not like `application` as the configuration file name, you can switch
You can also refer to an explicit location by using the `spring.config.location` environment property (which is a comma-separated list of directory locations or file paths).
You can also refer to an explicit location by using the `spring.config.location` environment property (which is a comma-separated list of directory locations or file paths).
The following example shows how to specify a different file name:
The following example shows how to specify a different file name:
@ -77,9 +77,12 @@ Each will be called in order with the `MongoClientSettings.Builder` that is used
You can set the configprop:spring.data.mongodb.uri[] property to change the URL and configure additional settings such as the _replica set_, as shown in the following example:
You can set the configprop:spring.data.mongodb.uri[] property to change the URL and configure additional settings such as the _replica set_, as shown in the following example:
@ -71,7 +71,7 @@ To do so, you need to <<features#features.external-config,enable the `debug` pro
For instance, if you are running your application by using `java -jar`, you can enable the `debug` property as follows:
For instance, if you are running your application by using `java -jar`, you can enable the `debug` property as follows:
[indent=0,subs="verbatim"]
[source,shell,indent=0,subs="verbatim"]
----
----
$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
----
----
@ -410,7 +410,7 @@ The first available implementation, `FlightRecorderApplicationStartup` is provid
It adds Spring-specific startup events to a Java Flight Recorder session and is meant for profiling applications and correlating their Spring context lifecycle with JVM events (such as allocations, GCs, class loading...).
It adds Spring-specific startup events to a Java Flight Recorder session and is meant for profiling applications and correlating their Spring context lifecycle with JVM events (such as allocations, GCs, class loading...).
Once configured, you can record data by running the application with the Flight Recorder enabled:
Once configured, you can record data by running the application with the Flight Recorder enabled:
@ -74,7 +74,7 @@ The annotation works by <<features#features.testing.spring-boot-applications.det
In addition to `@SpringBootTest` a number of other annotations are also provided for <<features#features.testing.spring-boot-applications.autoconfigured-tests,testing more specific slices>> of an application.
In addition to `@SpringBootTest` a number of other annotations are also provided for <<features#features.testing.spring-boot-applications.autoconfigured-tests,testing more specific slices>> of an application.
TIP: If you are using JUnit 4, don't forget to also add `@RunWith(SpringRunner.class)` to your test, otherwise the annotations will be ignored.
TIP: If you are using JUnit 4, don't forget to also add `@RunWith(SpringRunner.class)` to your test, otherwise the annotations will be ignored.
If you are using JUnit 5, there's no need to add the equivalent `@ExtendWith(SpringExtension.class)` as `@SpringBootTest` and the other `@…Test` annotations are already annotated with it.
If you are using JUnit 5, there's no need to add the equivalent `@ExtendWith(SpringExtension.class)` as `@SpringBootTest` and the other `@...Test` annotations are already annotated with it.
By default, `@SpringBootTest` will not start a server.
By default, `@SpringBootTest` will not start a server.
You can use the `webEnvironment` attribute of `@SpringBootTest` to further refine how your tests run:
You can use the `webEnvironment` attribute of `@SpringBootTest` to further refine how your tests run:
@ -4,7 +4,7 @@ Spring Boot can be used with "`classic`" Java development tools or installed as
Either way, you need https://www.java.com[Java SDK v1.8] or higher.
Either way, you need https://www.java.com[Java SDK v1.8] or higher.
Before you begin, you should check your current Java installation by using the following command:
Before you begin, you should check your current Java installation by using the following command:
[indent=0]
[source,shell,indent=0,subs="verbatim"]
----
----
$ java -version
$ java -version
----
----
@ -93,7 +93,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI.
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands:
Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands:
@ -218,7 +218,7 @@ See "`<<features#features.external-config.yaml>>`" in the '`Spring Boot features
The Spring `Environment` has an API for this, but you would normally set a System property (configprop:spring.profiles.active[]) or an OS environment variable (configprop:spring.profiles.active[format=envvar]).
The Spring `Environment` has an API for this, but you would normally set a System property (configprop:spring.profiles.active[]) or an OS environment variable (configprop:spring.profiles.active[format=envvar]).
Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows:
Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows:
The following table lists the various `@…Test` annotations that can be used to test slices of your application and the auto-configuration that they import by default:
The following table lists the various `@...Test` annotations that can be used to test slices of your application and the auto-configuration that they import by default:
@ -30,7 +30,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
=== Running as a Packaged Application
=== Running as a Packaged Application
If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using `java -jar`, as shown in the following example:
If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using `java -jar`, as shown in the following example: