qm332207252
V2EX  ›  Java

spring 自定义配置文件多环境切换

  •  
  •   qm332207252 · Feb 17, 2022 · 2824 views
    This topic created in 1558 days ago, the information mentioned may be changed or developed.

    spring 自定义配置文件,使用@PropertySource注解,然后多环境切换,比如redis-dev.properties,redis-test.properties...,使用@Value获取属性,idea 能够很好的支持通过点击@Value里配置的值跳转指定配置文件指定属性上,有什么好的方式吗?

    6 replies    2022-02-17 11:20:09 +08:00
    tunzao
        1
    tunzao  
       Feb 17, 2022
    Spring profile
    qm332207252
        2
    qm332207252  
    OP
       Feb 17, 2022
    @tunzao 是自定义配置文件,不是 spring 系统配置文件
    javapythongo
        3
    javapythongo  
       Feb 17, 2022
    配置中心
    Mjhhh
        4
    Mjhhh  
       Feb 17, 2022
    nacos
    BiChengfei
        5
    BiChengfei  
       Feb 17, 2022
    https://www.cnblogs.com/suizhikuo/p/12909007.html
    ```
    @PropertySource( name="jdbc-bainuo-dev.properties",value= {"classpath:config/jdbc-bainuo-$ {spring.profiles.active}.properties"},ignoreResourceNotFound=false,encoding="UTF-8")
    ```
    你想要的应该是这个吧
    jorneyr
        6
    jorneyr  
       Feb 17, 2022
    spring.config.import=optional:file:./dev.properties: This will trigger the import of a dev.properties file in current directory (if such a file exists). Values from the imported dev.properties will take precedence over the file that triggered the import. In the above example, the dev.properties could redefine
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1077 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 18:17 · PVG 02:17 · LAX 11:17 · JFK 14:17
    ♥ Do have faith in what you're doing.