Polish
This commit is contained in:
parent
711a0c19e6
commit
65c00f373a
|
|
@ -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:
|
||||
|
||||
[source,properties,indent=0,subs="verbatim",configprops]
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
management.info.git.enabled=false
|
||||
management:
|
||||
info:
|
||||
git:
|
||||
enabled: false
|
||||
----
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ To use the module, you need to declare an additional `spring-boot` namespace in
|
|||
|
||||
You need to remember to start Ant using the `-lib` option, as shown in the following example:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar>
|
||||
----
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
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:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
[source,groovy,pending-extract=true,indent=0,subs="verbatim"]
|
||||
----
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class Application implements CommandLineRunner {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Once you have installed the CLI, you can run it by typing `spring` and pressing Enter at the command line.
|
||||
If you run `spring` without any arguments, a help screen is displayed, as follows:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ spring
|
||||
usage: spring [--help] [--version]
|
||||
|
|
@ -19,7 +19,7 @@ If you run `spring` without any arguments, a help screen is displayed, as follow
|
|||
|
||||
You can type `spring help` to get more details about any of the supported commands, as shown in the following example:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ spring help run
|
||||
spring run - Run a spring groovy script
|
||||
|
|
@ -41,7 +41,7 @@ You can type `spring help` to get more details about any of the supported comman
|
|||
|
||||
The `version` command provides a quick way to check which version of Spring Boot you are using, as follows:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ spring version
|
||||
Spring CLI v{spring-boot-version}
|
||||
|
|
@ -64,21 +64,21 @@ include::{docs-groovy}/cli/usingthecli/run/WebApplication.groovy[tag=*]
|
|||
|
||||
To compile and run the application, type the following command:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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.
|
||||
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
|
||||
----
|
||||
|
|
@ -212,7 +212,7 @@ Doing so lets you use multiple files from a single directory, as shown in the fo
|
|||
=== 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:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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
|
||||
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
|
||||
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`.
|
||||
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
|
||||
=======================================
|
||||
|
|
@ -282,7 +282,7 @@ The `init` command supports many options.
|
|||
See the `help` output for more details.
|
||||
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
|
||||
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.
|
||||
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:
|
||||
|
||||
[indent=0,subs="verbatim,quotes,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
$ spring shell
|
||||
*Spring Boot* (v{spring-boot-version})
|
||||
|
|
@ -305,7 +305,7 @@ If you do not use either of these shells (perhaps you are a Windows user), you c
|
|||
|
||||
From inside the embedded shell, you can run other commands directly:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ version
|
||||
Spring CLI v{spring-boot-version}
|
||||
|
|
@ -322,7 +322,7 @@ To exit the embedded shell, press `ctrl-c`.
|
|||
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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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.
|
||||
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
|
||||
----
|
||||
|
|
@ -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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ spring uninstall --all
|
||||
----
|
||||
|
|
|
|||
|
|
@ -66,12 +66,13 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
|
|||
----
|
||||
|
||||
Each "`property`" is a configuration item that the user specifies with a given value.
|
||||
For example, `server.port` and `server.address` might be specified in `application.properties`, as follows:
|
||||
For example, `server.port` and `server.address` might be specified in your `application.properties`/`application.yaml`, as follows:
|
||||
|
||||
[source,properties,indent=0,subs="verbatim",configprops]
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
server.port=9090
|
||||
server.address=127.0.0.1
|
||||
server:
|
||||
port: 9090
|
||||
address: 127.0.0.1
|
||||
----
|
||||
|
||||
The "`groups`" are higher level items that do not themselves specify a value but instead provide a contextual grouping for properties.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
The following line shows using the `cf push` command to deploy an application:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ cf push acloudyspringtime -p target/demo-0.0.1-SNAPSHOT.jar
|
||||
----
|
||||
|
|
@ -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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ cf apps
|
||||
Getting applications in ...
|
||||
|
|
@ -126,14 +126,14 @@ The preStop handler can be configured via the PodSpec in the pod's configuration
|
|||
|
||||
[source,yml,indent=0,subs="verbatim"]
|
||||
----
|
||||
spec:
|
||||
containers:
|
||||
- name: example-container
|
||||
image: example-image
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
command: ["sh", "-c", "sleep 10"]
|
||||
spec:
|
||||
containers:
|
||||
- name: example-container
|
||||
image: example-image
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
command: ["sh", "-c", "sleep 10"]
|
||||
----
|
||||
|
||||
Once the pre-stop hook has completed, SIGTERM will be sent to the container and <<features#features.graceful-shutdown,graceful shutdown>> will begin, allowing any remaining in-flight requests to complete.
|
||||
|
|
@ -161,7 +161,7 @@ The `$PORT` environment variable is assigned to us by the Heroku PaaS.
|
|||
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:
|
||||
|
||||
[indent=0,subs="verbatim,quotes"]
|
||||
[source,shell,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
$ 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:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ boxfuse run myapp-1.0.jar -env=prod
|
||||
----
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ Certain PaaS implementations may also choose to unpack archives before they run.
|
|||
For example, Cloud Foundry operates this way.
|
||||
One way to run an unpacked archive is by starting the appropriate launcher, as follows:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ jar -xf myapp.jar
|
||||
$ java org.springframework.boot.loader.JarLauncher
|
||||
|
|
@ -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:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ jar -xf myapp.jar
|
||||
$ java -cp BOOT-INF/classes:BOOT-INF/lib/* com.example.MyApplication
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
|
||||
----
|
||||
|
|
@ -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.
|
||||
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
|
||||
----
|
||||
|
|
@ -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.
|
||||
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>
|
||||
----
|
||||
|
|
@ -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.
|
||||
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
|
||||
----
|
||||
|
|
@ -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.
|
||||
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
|
||||
----
|
||||
|
|
@ -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.
|
||||
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
|
||||
----
|
||||
|
|
@ -134,7 +134,7 @@ If root is used to control the application's service and you <<deployment#deploy
|
|||
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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ chmod 400 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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ systemctl enable myapp.service
|
||||
----
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ When your application starts, any `spring.application.json` or `SPRING_APPLICATI
|
|||
|
||||
For example, the `SPRING_APPLICATION_JSON` property can be supplied on the command line in a UN{asterisk}X shell as an environment variable:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ SPRING_APPLICATION_JSON='{"my":{"name":"test"}}' java -jar myapp.jar
|
||||
----
|
||||
|
|
@ -80,14 +80,14 @@ In the preceding example, you end up with `my.name=test` in the Spring `Environm
|
|||
|
||||
The same JSON can also be provided as a system property:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -Dspring.application.json='{"my":{"name":"test"}}' -jar myapp.jar
|
||||
----
|
||||
|
||||
Or you could supply the JSON by using a command line argument:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myapp.jar --spring.application.json='{"my":{"name":"test"}}'
|
||||
----
|
||||
|
|
@ -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).
|
||||
The following example shows how to specify a different file name:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myproject.jar --spring.config.name=myproject
|
||||
----
|
||||
|
||||
The following example shows how to specify two locations:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myproject.jar --spring.config.location=optional:classpath:/default.properties,optional:classpath:/override.properties
|
||||
----
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ The default log configuration echoes messages to the console as they are written
|
|||
By default, `ERROR`-level, `WARN`-level, and `INFO`-level messages are logged.
|
||||
You can also enable a "`debug`" mode by starting your application with a `--debug` flag.
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myapp.jar --debug
|
||||
----
|
||||
|
|
@ -107,7 +107,7 @@ For example, to make the text yellow, use the following setting:
|
|||
|
||||
[source,indent=0,subs="verbatim"]
|
||||
----
|
||||
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
|
||||
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
|
||||
----
|
||||
|
||||
The following colors and styles are supported:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
[source,properties,indent=0,subs="verbatim",configprops]
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
uri: "mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test"
|
||||
----
|
||||
|
||||
Alternatively, you can specify connection details using discrete properties.
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ 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...).
|
||||
Once configured, you can record data by running the application with the Flight Recorder enabled:
|
||||
|
||||
[source,bash,indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar demo.jar
|
||||
----
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ For instance, to use JDBC as the back-end store, you can configure your applicat
|
|||
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
spring:
|
||||
session:
|
||||
store-type: "jdbc"
|
||||
spring:
|
||||
session:
|
||||
store-type: "jdbc"
|
||||
----
|
||||
|
||||
TIP: You can disable Spring Session by setting the `store-type` to `none`.
|
||||
|
|
@ -35,10 +35,10 @@ For instance, it is possible to customize the name of the table for the JDBC sto
|
|||
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
spring:
|
||||
session:
|
||||
jdbc:
|
||||
table-name: "SESSIONS"
|
||||
spring:
|
||||
session:
|
||||
jdbc:
|
||||
table-name: "SESSIONS"
|
||||
----
|
||||
|
||||
For setting the timeout of the session you can use the configprop:spring.session.timeout[] property.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
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.
|
||||
You can use the `webEnvironment` attribute of `@SpringBootTest` to further refine how your tests run:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Check the https://github.com/spring-io/start.spring.io/blob/main/USING.adoc[star
|
|||
|
||||
Before we begin, open a terminal and run the following commands to ensure that you have valid versions of Java and Maven installed:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -version
|
||||
java version "1.8.0_102"
|
||||
|
|
@ -23,7 +23,7 @@ Before we begin, open a terminal and run the following commands to ensure that y
|
|||
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
|
||||
----
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ mvn -v
|
||||
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T14:33:14-04:00)
|
||||
|
|
@ -119,7 +119,7 @@ Other "`Starters`" provide dependencies that you are likely to need when develop
|
|||
Since we are developing a web application, we add a `spring-boot-starter-web` dependency.
|
||||
Before that, we can look at what we currently have by running the following command:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ mvn dependency:tree
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ Since you used the `spring-boot-starter-parent` POM, you have a useful `run` goa
|
|||
Type `mvn spring-boot:run` from the root project directory to start the application.
|
||||
You should see output similar to the following:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ mvn spring-boot:run
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin documentation] fo
|
|||
|
||||
Save your `pom.xml` and run `mvn package` from the command line, as follows:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ mvn package
|
||||
|
||||
|
|
@ -298,7 +298,7 @@ If you look in the `target` directory, you should see `myproject-0.0.1-SNAPSHOT.
|
|||
The file should be around 10 MB in size.
|
||||
If you want to peek inside, you can use `jar tvf`, as follows:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
|
||||
----
|
||||
|
|
@ -308,7 +308,7 @@ This is the original jar file that Maven created before it was repackaged by Spr
|
|||
|
||||
To run that application, use the `java -jar` command, as follows:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
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
|
||||
----
|
||||
|
|
@ -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.
|
||||
Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ sdk install springboot
|
||||
$ spring --version
|
||||
|
|
@ -102,7 +102,7 @@ Get SDKMAN! from https://sdkman.io and install Spring Boot by using the followin
|
|||
|
||||
If you develop features for the CLI and want access to the version you built, use the following commands:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ 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
|
||||
|
|
@ -115,7 +115,7 @@ It points at your target build location, so every time you rebuild Spring Boot,
|
|||
|
||||
You can see it by running the following command:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
$ sdk ls springboot
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ You can see it by running the following command:
|
|||
==== OSX Homebrew Installation
|
||||
If you are on a Mac and use https://brew.sh/[Homebrew], you can install the Spring Boot CLI by using the following commands:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ brew tap spring-io/tap
|
||||
$ brew install spring-boot
|
||||
|
|
@ -155,7 +155,7 @@ In that case, run `brew update` and try again.
|
|||
==== MacPorts Installation
|
||||
If you are on a Mac and use https://www.macports.org/[MacPorts], you can install the Spring Boot CLI by using the following command:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ sudo port install spring-boot-cli
|
||||
----
|
||||
|
|
@ -169,7 +169,7 @@ You can `source` the script (also named `spring`) in any shell or put it in your
|
|||
On a Debian system, the system-wide scripts are in `/shell-completion/bash` and all scripts in that directory are executed when a new shell starts.
|
||||
For example, to run the script manually if you have installed by using SDKMAN!, use the following commands:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
|
||||
$ spring <HIT TAB HERE>
|
||||
|
|
@ -217,7 +217,7 @@ To start, create a file called `app.groovy`, as follows:
|
|||
|
||||
Then run it from a shell, as follows:
|
||||
|
||||
[indent=0]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ spring run app.groovy
|
||||
----
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Spring Boot converts any command line argument starting with `--` to a property
|
|||
This should not be used to pass arguments to batch jobs.
|
||||
To specify batch arguments on the command line, use the regular format (i.e. without `--`), as shown in the following example:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myapp.jar someParameter=someValue anotherParameter=anotherValue
|
||||
----
|
||||
|
|
@ -43,7 +43,7 @@ To specify batch arguments on the command line, use the regular format (i.e. wit
|
|||
If you specify a property of the `Environment` on the command line, it is ignored by the job.
|
||||
Consider the following command:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar myapp.jar --server.port=7070 someParameter=someValue
|
||||
----
|
||||
|
|
|
|||
|
|
@ -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]).
|
||||
Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
|
||||
----
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ If you use Maven, the following example marks the servlet container (Tomcat, in
|
|||
[source,xml,indent=0,subs="verbatim"]
|
||||
----
|
||||
<dependencies>
|
||||
<!-- … -->
|
||||
<!-- ... -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- … -->
|
||||
<!-- ... -->
|
||||
</dependencies>
|
||||
----
|
||||
|
||||
|
|
@ -57,9 +57,9 @@ If you use Gradle, the following example marks the servlet container (Tomcat, in
|
|||
[source,gradle,indent=0,subs="verbatim"]
|
||||
----
|
||||
dependencies {
|
||||
// …
|
||||
// ...
|
||||
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
|
||||
// …
|
||||
// ...
|
||||
}
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ include::attributes.adoc[]
|
|||
|
||||
|
||||
|
||||
This appendix describes the `@…Test` auto-configuration annotations that Spring Boot provides to test slices of your application.
|
||||
This appendix describes the `@...Test` auto-configuration annotations that Spring Boot provides to test slices of your application.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[[test-auto-configuration.slices]]
|
||||
== Test Slices
|
||||
|
||||
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:
|
||||
|
||||
include::documented-slices.adoc[]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
|
|||
=== 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:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -jar target/myapplication-0.0.1-SNAPSHOT.jar
|
||||
----
|
||||
|
|
@ -38,7 +38,7 @@ If you use the Spring Boot Maven or Gradle plugins to create an executable jar,
|
|||
It is also possible to run a packaged application with remote debugging support enabled.
|
||||
Doing so lets you attach a debugger to your packaged application, as shown in the following example:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
|
||||
-jar target/myapplication-0.0.1-SNAPSHOT.jar
|
||||
|
|
@ -52,14 +52,14 @@ The Spring Boot Maven plugin includes a `run` goal that can be used to quickly c
|
|||
Applications run in an exploded form, as they do in your IDE.
|
||||
The following example shows a typical Maven command to run a Spring Boot application:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ mvn spring-boot:run
|
||||
----
|
||||
|
||||
You might also want to use the `MAVEN_OPTS` operating system environment variable, as shown in the following example:
|
||||
|
||||
[indent=0,subs="verbatim"]
|
||||
[source,shell,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ export MAVEN_OPTS=-Xmx1024m
|
||||
----
|
||||
|
|
|
|||
Loading…
Reference in New Issue