首页 > 解决方案 > 自定义 PropertyPlaceholderConfigurer 不解析嵌入的属性值

问题描述

我有一个 Spring 4.3 自定义 PropertyPlaceholderConfigurer,它在注入之前对从属性文件中读取的值进行额外处理:

public class MyPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{ 

    @Override
    protected String convertPropertyValue(final String originalValue) { ... }

    @Override
    protected String resolveSystemProperty(final String key) {
       return convertPropertyValue(super.resolveSystemProperty(key));
    }
}

我的问题是注解注入属性值的bean字段,例如。@Value("${some_property}"), 实际上是从属性源读取的原始值注入的,而没有我的自定义处理。

标签: javaspringproperty-placeholder

解决方案


经过一些调试后,我发现我也应该覆盖com.ec.survey.security.SafePasswordPropertyPlaceholderConfigurer#resolvePlaceholder


推荐阅读