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

2022-02-17 09:58:11 +08:00
 qm332207252

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

1789 次点击
所在节点    Java
6 条回复
tunzao
2022-02-17 10:01:15 +08:00
Spring profile
qm332207252
2022-02-17 10:03:32 +08:00
@tunzao 是自定义配置文件,不是 spring 系统配置文件
javapythongo
2022-02-17 10:08:56 +08:00
配置中心
Mjhhh
2022-02-17 10:18:34 +08:00
nacos
BiChengfei
2022-02-17 10:26:25 +08:00
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
2022-02-17 11:20:09 +08:00
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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/834414

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX