SpringBoot 多Profile使用与切换方式
Spring中Profile对不同环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境。
文件名格式:application-{profile}.properties可以建立多个properties(yaml)文件来不断的切换
application-dev.properties
server.port=8082
application-prod.properties
server.port=8083
application.properties
server.port=8081spring.profiles.active=dev
文件名格式:application-{profile}.yaml
server: port: 8082spring: profiles: active: dev---spring: profiles: devserver: port: 8083---spring: profiles: prodserver: port: 8084---spring: profiles: default (未指定时默认使用的配置)server: port: 80激活方式:
yaml中:spring: profiles: active: dev 或properties中:spring.profiles.active=dev运行时:
在打包后运行的时候,添加参数:
java -jar spring-boot.jar --spring.profiles.active=dev;
tomcat 中 catalina.bat(.sh中不用“set”) 添加JAVA_OPS。通过设置active选择不同配置文件:set JAVA_OPTS='-Dspring.profiles.active=test'
web.xml方式
spring.profiles.active prod标注方式(junit单元测试非常实用)@ActiveProfiles({“dev”})
到此这篇关于SpringBoot 多Profile使用与切换方式的文章就介绍到这了,更多相关SpringBoot 多Profile使用与切换内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章:
1. 《CSS3实战》笔记--渐变设计(一)2. XML在语音合成中的应用3. 用css截取字符的几种方法详解(css排版隐藏溢出文本)4. CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera5. chatGPT教我写compose函数的详细过程6. Vue Element UI 表单自定义校验规则及使用7. 在 XSL/XSLT 中实现随机排序8. JavaScript避免嵌套代码浅析9. asp(vbs)Rs.Open和Conn.Execute的详解和区别及&H0001的说明10. CSS3实例分享之多重背景的实现(Multiple backgrounds)
