JAR包resources中有两个目录用于放properties
develop(开发环境)、product(生产环境),包含文件default.properties、其他.properties
某项目依赖该JAR包
resources结构与JAR包相同,并包含local.properties、其他properties
spring.xml使用下面方式 根据jdk中设置的-Denvironment=product判断是否是生产环境,来切换properties
<context:property-placeholder location="classpath*:#{systemProperties['environment'] ?: 'develop'}/*.properties" file-encoding="UTF-8" ignore-resource-not-found="true" ignore-unresolvable="true" local-override="false"></context:property-placeholder>
请问我如果在local.properties中配置某些属性用以覆盖jar包中default.properties中的属性应该怎么配置
上面的配置无法覆盖(因为local.properties先于default.properties读取)。
老样子 自问自答
<context:property-placeholder order="1" location="classpath:#{systemProperties['environment'] ?: 'develop'}/default.properties,classpath:#{systemProperties['environment'] ?: 'develop'}/local.properties" file-encoding="UTF-8" ignore-resource-not-found="true" ignore-unresolvable="true" local-override="false"></context:property-placeholder> <context:property-placeholder order="2" location="classpath*:#{systemProperties['environment'] ?: 'develop'}/*.properties" file-encoding="UTF-8" ignore-resource-not-found="true" ignore-unresolvable="true" local-override="false"></context:property-placeholder>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。