Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Springboot start receiving parameters

Shulou Source: shulou.com Published: 2022-06-03 07:05:20 10月25日 Update

Springboot startup can pass startup parameters to the program through the java-jar xxx.jar parameter.

Passing parameters through args [] is very inelegant, and different systems will have singularities. The windows system will write a line of identification in the parameters, but the Linux system will not, and a few parameters will be arranged according to the number of digits in the array.

Here's an elegant way to inject attributes through @ Value with the help of attributes in application.properties.

The code is as follows: @ Componentbr/ > @ Component

@ Value ("${contextPath}") private String contextPath;public String getPath () {return contextPath;}

}

The installation package path defaults to empty

ContextPath=

Start with java-jar xxx.jar-- contextPath= "/ home/app/"

Tags: Parameters systems elegance properties differences singularities one line code digits can be passed that is arrays ways times identifiers programs paths Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi Apple OPPO Reno Huawei