SpringBoot多Profile怎么使用及切换的方式

发布时间:2022-02-24 10:03:38 作者:iii
来源:亿速云 阅读:150

这篇文章主要介绍“SpringBoot多Profile怎么使用及切换的方式”,在日常操作中,相信很多人在SpringBoot多Profile怎么使用及切换的方式问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”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=8081
spring.profiles.active=dev

文件名格式:application-{profile}.yaml

server:
  port: 8082
spring:
  profiles:
    active: dev
---
spring:
  profiles: dev
server:
  port: 8083
---
spring:
  profiles: prod
server:
  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怎么使用及切换的方式”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 多浏览器判断,切换及使用
  2. springboot如何实现profile多环境配置切换

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot profile

上一篇:婚礼小程序开发的基本功能是什么

下一篇:SpringBoot框架怎么配置ShedLock分布式定时任务

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》