-
启动springboot的jar包
java -jar springboot.jar
-
多环境启动springboot的jar包
分别写出多个环境下的配置文件,命名如下 application-xxx.properties
- 可在application.properties中用
spring.profiles.active=test
来激活对应的环境 - 在linux环境用命令行
java -jar springboot.jar --spring.profiles.active=test
来激活对应的环境 - 在idea里,也可以模拟启动,
-Dspring.profiles.active=test
- 有时候需要的值都没在配置文件里配,然后又懒得重新打包,这时候,就可用通过命令行的方式把值从外部传入。
最简单的方式,比如修改端口。java -jar springboot.jar --server.port=8888
再比如,我在配置文件里有
webhook_url=www.baidu.com的一个常量,而我现在需要去修改这个常量又不想去重新打包,就可以java -jar springboot.jar --webhook_url=http://www.qq.com
@RestController
public class MainController {
@Value("${webhook_url}")
private String webhookUrl;
@GetMapping("/main")
public String main() {
return webhookUrl;
}
}
启动命令,
java -jar hello-spring-boot-0.0.1-SNAPSHOT.jar --webhook_url=http://www.qq.com