V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
BraveXaiver
V2EX  ›  问与答

请问如何将 `application.yml` 中 include 进来的 profile 在 `application-local.yml` 下删去?

  •  
  •   BraveXaiver · 128 天前 · 692 次点击
    这是一个创建于 128 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如说关于 API Auth 有很多配置,且对于开发环境,内部测试环境和预生产环境,生产环境均相同,所以它们都集中在 `application-auth.yml` 中,并通过 `application.yml` 中写 `spring.profiles.include: auth` 来统一引入。

    但在本地运行这个 APP 的时候,这些 API Auth 的功能和配置完全不需要反而还有害,此时我想在 `application-local.yml` 中移除 auth 这个 profile 。

    请问能做到吗?谢谢。
    8 条回复    2023-12-22 10:18:27 +08:00
    wolfie
        1
    wolfie  
       128 天前
    改用 spring.profiles.active ,本地启动参数覆盖手动排除特定配置。
    BraveXaiver
        2
    BraveXaiver  
    OP
       128 天前
    @wolfie 我用 IDEA 启动的时候指定了使用 local 这个 profile ,但 auth 还是生效了。感觉最终生效的 profile 是 active+include
    wolfie
        3
    wolfie  
       128 天前
    @BraveXaiver
    去掉 include ,改用 active
    oneisall8955
        4
    oneisall8955  
       128 天前 via Android
    启动可以配置-Dspring.profiles.include=xxx 参数覆盖配置
    BraveXaiver
        5
    BraveXaiver  
    OP
       128 天前
    @wolfie 你的意思是直接在 application.yml 中改为使用 spring.profiles.active: auth? emm ,但这里必须用 include ,不然又会有其他问题。
    BraveXaiver
        6
    BraveXaiver  
    OP
       128 天前
    @oneisall8955 好的,我试试,我这里是想移除的话,那就什么都不写放等号右边?
    BraveXaiver
        7
    BraveXaiver  
    OP
       128 天前
    @oneisall8955 不行,我加了 -Dspring.profiles.include=local, auth 还是被弄进来了

    2023-12-21 23:53:37.476 INFO 2740 --- [ restartedMain] c.e.s.SpringBootDemoApplication : The following 2 profiles are active: "local", "auth"
    ChoateYao
        8
    ChoateYao  
       127 天前   ❤️ 1
    不知道你的版本是多少,我在 Springboot 2.7 上能使用 group 的功能,不同的环境可以定义使用不同配置文件

    ```yml
    spring:
    profiles:
    active: local
    group:
    local:
    - datasource
    dev:
    - dev-datasouce
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1063 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 18:28 · PVG 02:28 · LAX 11:28 · JFK 14:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.