开发者社区 问答 正文

问个spring context:property-placeholder应用的问题:报错

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读取)。

展开
收起
kun坤 2020-06-08 17:42:42 899 分享 版权
1 条回答
写回答
取消 提交回答
  • 老样子 自问自答

    <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>
    2020-06-08 17:42:48
    赞同 展开评论