You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "shifefiei (GitHub)" <gi...@apache.org> on 2019/12/13 13:54:43 UTC

[GitHub] [dubbo] shifefiei commented on issue #5439: 无法解析站位符

为题已解决,谢谢
package com.xrxs.attendance.entry.config;

import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * Created by sff on 2019-12-13 21:03
 */
@Component
public class AttendanceDubboRegistry implements BeanDefinitionRegistryPostProcessor, EnvironmentAware {

    @Autowired
    private Environment env;

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        BeanDefinition registryConfig = registry.getBeanDefinition("com.alibaba.dubbo.config.RegistryConfig");
        String address = env.getProperty("dubbo.zk.host");
        String group = env.getProperty("dubbo.zk.group");
        group = "dubbo/" + group;

        MutablePropertyValues propertyValues = registryConfig.getPropertyValues();
        propertyValues.add("address", address);
        propertyValues.add("group", group);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        RegistryConfig registryConfig = beanFactory.getBean(RegistryConfig.class);

        String group = env.getProperty("dubbo.zk.group");
        group = "dubbo/" + group;

        String address = env.getProperty("dubbo.zk.host");
        registryConfig.setAddress(address);
        registryConfig.setGroup(group);
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.env = environment;
    }
}
自己手动注册解析进去

[ Full content available at: https://github.com/apache/dubbo/issues/5439 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org