主页 > 人工智能  > 

springBoot配置文件(四)application常见配置


一、命令行参数:

1、server.address=xxx.xxx.xx.xxx  

    服务器绑定ip地址,多网卡时可以指定

2、server.port=xxx 

 可以指定springboot内嵌容器启动的端口,默认使用tomcat容器时在8080端口,右键run- java application/springboot..,可以支持不同的容器,在引入不同的依赖时。当server.port=0时,表示自动扫面获取一个可用的端口。

3、ssl的安全访问配置:

server.port=8443 #ssl的安全访问配置 server.ssl.key-store=classpath:keystore.jks server.ssl.key-store-password=secret server.ssl.key-password=another-secret

注意: 目前spring-boot不支持http和https同时启用的情况,只支持使用其中一个,如果需要同时使用,可以使用其他形式的实现方式。

该部分对应org.springframework.boot.autoconfigure.webServerProperties类。

此外还有一些不是很常用的如:server.http2.enable=true/false//该属性可以支持http2的协议类型,目前只支持tomcat和undertow的容器并且需要JDK1.8+,官文上对于内嵌tomcat的配置参数也有很多。

二、开发/测试/生产环境配置:

1、语法:

spring.profiles.active=xxxx

  //该系统变量可以指明要使用的配置文件,一般应用于多环境配置分离,如生产环境(production),开发环境(development),测试环境(test)等,可以自定义,如开发环境配置文件为application-dev.properties,则spring.profiles.active=dev,在启动时会加载application-dev.properties配置文件。一般约定:

application-dev.properties开发环境配置文件 application-test.properties测试环境配置文件 application-prod.properties生产环境配置文件

2、使用方法:

(1)手动指定:这种方法切换环境需要修改配置文件,不够方便

spring.profiles.active = {profile} #如spring.profiles.active = prod​

 (2)打包自动指定。

spring.profiles.active=@spring.profiles.active@

3、demo:

标签:

springBoot配置文件(四)application常见配置由讯客互联人工智能栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“springBoot配置文件(四)application常见配置