0

在将 spring 框架迁移到 4.2.8(自 4.1.6 版起)后,我无法通过自定义 PropertyPlaceholder 加载配置。

<bean id="customPlaceHolderConfigurer" class="xxx.CustomPlaceHolderConfigurer">
    <property name="order" value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE + 10}" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>

<jaxws:client id="wsBusinessService" address="${pf:WS_URL}/soap/ws" serviceClass="xxx.WSBusinessService" />

和自定义占位符

public class CustomPlaceHolderConfigurer extends PropertyPlaceholderConfigurer {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomPlaceHolderConfigurer.class);

    @Override
    protected String resolvePlaceholder(final String pPlaceholder, final Properties pProps) {
        String value = null;
        if (pPlaceholder != null) {
            if (CIStringUtils.startsWith(pPlaceholder, "pf")) {
                String propertyKey = StringUtils.substring(pPlaceholder, 3);
                if (propertyKey.contains(":")) {
                    String defaultValue = StringUtils.substringAfter(propertyKey, ":");
                    String newKey = StringUtils.substringBefore(propertyKey, ":");
                    value = Plateforme.getProperty(newKey, defaultValue);
                } else {
                    value = Plateforme.getProperty(propertyKey);
                }
            }
        }
        LOGGER.debug("placeholder '{}' resolved to '{}'", pPlaceholder, value);
        return value;
    }

}

当我启动应用程序时,我得到以下日志:

2016-12-13T15:52:12,448 [localhost-startStop-2] DEBUG CustomPlaceHolderConfigurer - placeholder 'pf:WS_URL' resolved to 'services.com'

但是 jaxws 抛出了一个异常,因为该属性没有被替换:« 找不到地址的管道启动器:${pf:WS_URL}/soap/ws 和传输:http: //schemas.xmlsoap.org/soap/http  »

了解到配置的加载顺序改成了spring 4.2.x,但是即使改了顺序也无法操作。(https://github.com/spring-projects/spring-framework/wiki/Migrating-to-Spring-Framework-4.x

Spring Framework 4.2 对配置类处理进行了显着的微调。与4.1相比,注册顺序可能存在细微差别;但是,这些被认为是对以前未明确定义的行为的修复。如果您依赖特定的顺序,例如通过名称覆盖 bean,请考虑使用 4.2 的新功能,特别是配置类上的 @Order 注释。

我试过了 :

#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE + 10} #{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE} -1 1

有没有人遇到过这个问题?

谢谢

4

0 回答 0