springboot web端口设置三种方式
所属分类 spring
浏览量 1964
三种方式
系统参数
-Dserver.port=9090
java -jar -Dserver.port=8090 app.jar
java -jar app.jar --server.port=9090
application.properties
server.port=9090
使用环境变量 SERVER_PORT
export SERVER_PORT=8090
java -jar app.jar
server.port=${PORT:8080}
自动映射
不需要使用 ${xxx}
server.port=8080
环境变量名自动映射规则:
配置属性:server.port
环境变量大写 + 下划线:SERVER_PORT
spring.application.name → 环境变量 SPRING_APPLICATION_NAME
my.config.age → 环境变量 MY_CONFIG_AGE
优先级从高到低 :
命令行参数
JVM 系统属性
系统环境变量
application 配置文件
确保该文件存在
eclipse src 里 可能会把
application*.yml
application*.yaml
application*.properties
排除掉
EmbeddedServletContainerCustomizer接口自定义
Spring Boot2.0以上版本EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替代
org.springframework.boot.web.server.ConfigurableWebServerFactory
org.springframework.boot.web.server.WebServerFactoryCustomizer
@Bean
public WebServerFactoryCustomizer webServerFactoryCustomizer(){
return new WebServerFactoryCustomizer() {
@Override
public void customize(ConfigurableWebServerFactory factory) {
factory.setPort(9090);
}
};
}
系统参数和接口自定义优先
上一篇
下一篇
java堆外内存回收机制
ConcurrentHashMap在jdk7和8中的区别
优秀投资者的十大特征
springboot2 actuator 使用
springboot2获取web端口
springboot2微服务实例