We all know that springboot's yml file can configure multiple environments, and you can directly specify which environment to use in application.yml.
For example: specify the dev environment
This is hard-coded in the configuration file.
So, how to dynamically specify it when starting the project?
In fact, you only need to add one more command at startup:
java -jar xxx.jar --spring.profiles.active=dev
Three ways to specify commands for SpringBoot startup projects
in the configuration file. Add the required command
in application.yml or application.properties as shown below: server.port=1118
java -jar thymeleaf.jar --server.port=9000
to the startup command line. This method can overwrite the contents of the original configuration file.
Note:
If followed by the --server.port=9000 command. But after successful startup, it is still 1118.
The reason why the port has not changed is that SpringApplication did not pass in the variable parameter (the second parameter) when starting.
java -Dserver.port=9000 -jar thymeleaf.jar
This method is to directly write the properties into the JVM as parameters of the JVM, regardless of whether you add it to the SpringBoot startup The port number can be modified even with the second parameter.
Description | |
---|---|
Specify the server port | |
Specify Running environment (usually dev, test, uat, prod) |
The above is the detailed content of How to use commands to dynamically specify the environment when starting a Springboot project. For more information, please follow other related articles on the PHP Chinese website!