栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Java

关于spring-profiles提示已弃用的问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

关于spring-profiles提示已弃用的问题

如果你使用Spring Boot 2.4及以上版本,你会发现Spring Boot中对多环境支持的配置项spring-profiles已经被弃用。

原因:官方为了增加 Kubernetes Volume 的配置支持而进行修改

官方文档:Config file processing in Spring Boot 2.4

翻译文档:Spring Boot 2.4 配置文件将加载机制大变化_pig_冷冷的博客-CSDN博客

        虽然提示已弃用,但它仍然可以进行配置运行,因此对多环境支持的配置有以下两种方法:

//第一种spring-profiles
//可以使用,但会提示已弃用

server:
  port: 8081
spring:
  profiles:
    active: dev

---
server:
  port: 8082
spring:
  profiles: test

---
server:
  port: 8083
spring:
  profiles: dev
//第二种spring-config-activate-on-profile
//spring-profiles已弃用的解决方法

server:
  port: 8081

---
server:
  port: 8082
Spring:
  config:
    activate:
      on-profile: test

---
server:
  port: 8083
spring:
  config:
    activate:
      on-profile: dev

        以上两种虽然都可以运行成功,但推荐第二种方法,原因是2.4版本中官方将配置文件的加载进行了修改更新,从而提升了对 Kubernetes 的原生支持。

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/785545.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号