zoukankan      html  css  js  c++  java
  • 以API 配置的方式来配置你的 Dubbo 应用

    package com.aswatson.csc.member.conf;
    
    import com.aswatson.csc.member.service.MemberCardService;
    import java.util.HashMap;
    import java.util.Map;
    import javax.annotation.PostConstruct;
    import org.apache.dubbo.config.ConfigCenterConfig;
    import org.apache.dubbo.config.RegistryConfig;
    import org.apache.dubbo.config.ServiceConfig;
    import org.apache.dubbo.rpc.model.ApplicationModel;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.stereotype.Component;
    
    /**
     * @Author Tim
     * @Date 2021/11/5 14:22
     */
    @Component
    public class DubboConfig {
    
        //可以动态配置memberCardService
        public DubboConfig(@Autowired ApplicationContext applicationContext, @Value("${dubbo.registry.protocol}") String protocol, @Value("${dubbo.registry.address}") String address)
            throws ClassNotFoundException {
    
            Object serviceObj = applicationContext.getBean("memberCardService");
            Class clazz = Class.forName("com.aswatson.csc.member.service.MemberCardService");
    
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress(protocol + "://" + address);
            ServiceConfig service = new ServiceConfig();
            service.setApplication(ApplicationModel.getConfigManager().getApplicationOrElseThrow());
            service.setRegistry(registryConfig);
            service.setInterface(clazz);
            service.setRef(serviceObj);
            service.setVersion("1.0");
            service.export();
        }
    
         //测试写死memberCardService
    //    public DubboConfig(@Autowired ApplicationContext applicationContext, @Value("${dubbo.registry.protocol}") String protocol, @Value("${dubbo.registry.address}") String address) {
    //        RegistryConfig registryConfig1 = new RegistryConfig();
    //        registryConfig1.setAddress(protocol + "://" + address);
    //        ServiceConfig<MemberCardService> service = new ServiceConfig<MemberCardService>();
    //        service.setApplication(ApplicationModel.getConfigManager().getApplicationOrElseThrow());
    //        service.setRegistry(registryConfig1);
    //        service.setInterface(MemberCardService.class);
    //        service.setRef((MemberCardService) applicationContext.getBean("memberCardService"));
    //        service.setVersion("1.0");
    //        service.export();
    //    }
    
    }
    路在脚下
  • 相关阅读:
    纯CSS绘制三角形(各种角度)
    富文本编辑器Quill(二)上传图片与视频
    富文本编辑器Quill(一)简单介绍
    Vue中使用Cropper.js裁剪图片
    Python使用LDAP做用户认证
    concurrent.futures进行并发编程
    Selenium及Headless Chrome抓取动态HTML页面
    七夕节快到了,做个图钉画以及学习下Pillow吧
    Python socket
    Python爬取视频(其实是一篇福利)
  • 原文地址:https://www.cnblogs.com/lgg20/p/15530432.html
Copyright © 2011-2022 走看看