Get the App
SLTechnology News&Howtos  ›  Development  › 

There are several ways to start springboot

Shulou Source: shulou.com Published: 2022-06-03 14:06:13 10月26日 Update

This article introduces the relevant knowledge of "there are several ways to start springboot". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There are three main ways to start spring-boot:

1. Run the class with main method

two。 Through the command line java-jar

3. Through the spring-boot-plugin way

First, execute the class with main method

This way is very simple, I mainly through the way of idea, to implement. When starting, this method will automatically load the configuration file under classpath.

Here is only a separate emphasis on classpath, in fact, spring-boot has its own loading path and priority, which will be released in the future.

@ RestController@EnableAutoConfigurationpublic class Example {@ RequestMapping ("/") public String home () {return "Hello World";} public static void main (String [] args) {/ * SpringApplication automatically loads the application.properties file. The specific loading path includes the following: *

* 1. A / config subdirectory of the current directory; * *

* 2. The Current Directory *

*

* 3. A classpath / config package *

*

4. The classpath root. *

* / SpringApplication.run (Example.class, args);}}

In idea, you can configure your own request parameters by configuring application.

Second, through the java-jar way

Java-jar jar_path-- param

Jar_path: refers to the storage path after the project is packaged as jar

-- param: for the parameters that need to be specified on the command line. For example:

Java-jar emample.jar-- server.port=8081

This command overrides the port configuration in application.properties by specifying the port number bound after the project starts on the startup line, because this command line argument

Third, start through spring-boot-plugin.

If you need to use the maven lookup normally, you need to add the following plug-in configuration to the maven project:

Org.springframework.boot spring-boot-maven-plugin

Note: because I specified the parent module spring-boot-starter-parent in the project. So I don't need to specify the plug-in version separately, and the parent module automatically matches the lookup version that matches the current spring-boot version.

Org.springframework.boot spring-boot-starter-parent 1.5.10.RELEASE

After the preparatory work is done, we need to go to the root directory of the project and execute

Mvn sprint-boot:run

This command starts the project normally, but how do you specify execution parameters for it?

Spring-boot:run the maven lookup specifies optional parameters that can be used in the plug-in home page:

By consulting the documentation, you can see the meaning and usage of specific options in the form of commands:

Mvn spring-boot:help-Ddetail

In the description of arguments, the main idea is that the specified parameters will be passed to the specific application, and if there are multiple parameters to be specified, they will be segmented with ",". The specific usage is specified by run.arguments:

Mvn spring-boot:run-Drun.arguments= "--server.port=8888"

"there are several ways to start springboot" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Mode parameter command project configuration plug-in version path middle finger content available through file method more module knowledge utility achievement next priority Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Docker Xiaomi macOS