Skip to content

[Enhancement] Resolving the placeholders of XML BeanDefinition in the Configuration Class#6079

Merged
mercyblitz merged 1 commit intoapache:masterfrom
mercyblitz:2.7.7-xml-bean-definitions
Apr 28, 2020
Merged

[Enhancement] Resolving the placeholders of XML BeanDefinition in the Configuration Class#6079
mercyblitz merged 1 commit intoapache:masterfrom
mercyblitz:2.7.7-xml-bean-definitions

Conversation

@mercyblitz
Copy link
Copy Markdown
Contributor

It does not work in Dubbo 2.7.6

    @Configuration
    @PropertySource("classpath:/META-INF/demo-provider.properties")
    @ImportResource(locations = "classpath:/org/apache/dubbo/config/spring/demo-provider.xml")
    static class XmlConfiguration {

    }

…BeanDefinition in the Configuration Class
@kylixs
Copy link
Copy Markdown
Member

kylixs commented Mar 4, 2021

此方案是在DubboBeanDefinitionParser中,使用environment.resolvePlaceholders解决一次placeholder,但此时PropertyPlaceholderConfigurer还没加载,可能导致xml配置解决结果不正确。
如当存在默认值的情况时,可能没有使用配置,而是使用默认值:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>app.properties</value>
    </property>
</bean>

<dubbo:registry address="${dubbo.registry.address:zookeeper://127.0.0.1:2182}"/>

app.properties:

dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service

上面的例子中,registry的address值为zookeeper://127.0.0.1:2182,属性没有正确注入。

似乎应该使用PropertySourcesPlaceholderConfigurer来解决此问题,ctrip Apollo自动注册了这个bean:

    BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
        PropertySourcesPlaceholderConfigurer.class, propertySourcesPlaceholderPropertyValues);

@kylixs kylixs mentioned this pull request Mar 19, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants