Spring boot Maven plug-in usage details

The spring boot Maven plug-in provides the following steps for using the spring boot application:

Repackaging: create an automatically executable jar or war file. It can replace conventional artifacts, or it can be attached to the build lifecycle using a separate classifier. Run: run your spring boot application with several options to pass parameters. Start and stop: integrate the spring boot application into the integration test phase so that the application starts before it. Build information: generate build information that can be used by the actuator.

Repackage an application

In order to repackage the application, you only need to Add a reference to the plug-in in XML. The specific configuration is as follows:

Repackage jars or wars built during the package phase of the Maven lifecycle, including any provided dependencies defined in the project.

Devtools are automatically excluded by default (you can use the excludedevtools property to control). In order for these jobs to match the war wrapper, the "spring boot devtools" dependency must be set to an optional or provided scope. The original (i.e. non executable) file is renamed to. Original by default, but you can also use a custom classifier to retain the original artifacts.

The spring boot Maven plug-in rewrites the configuration. In particular, it manages the main class and start class entries. Therefore, if the default values do not work, they must be configured (not in the jar plug-in). The main class is actually controlled by the layout attribute of the boot plug-in. Example:

This layout property is the base archive type ((jar or war). It can be used in the following layouts:

Jar: General executable jar layout. War: executable war layout. The provided dependencies are placed in WEB-INF / lib to avoid conflicts when deployed in the servlet container. Zip (alias of DIR): similar to the jar layout using propertieslauncher. Module: bundle dependencies (excluding the scope provided) and project resources, and do not bundle the boot loader. None: bundle all dependencies and resources, and do not bundle the boot loader.

Run application

The spring boot Maven plug-in can be used to start an application from the command line. The specific commands are as follows:

mvn spring-boot:run

By default, the application executes directly from the Maven JVM. If you need to run in a forked process, you can use the 'fork' option. Bifurcation also occurs if the 'jvmarguments' or' agent 'option is specified, or if devtools is present. If you need to specify some JVM parameters (that is, for debugging purposes), you can use the jvmarguments parameter. For convenience, the configuration file to be enabled is handled by a specific property (configuration file).

Using integration testing

To ensure that the life cycle of spring boot applications is properly managed in integration testing, you can use the following startup and termination methods:

You can also configure more advanced settings to skip integration tests when setting specific properties:

Note: if you run MVN verify - DIT Skip = true, the integration test will be completely skipped.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>