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();
// } }

以API 配置的方式来配置你的 Dubbo 应用的更多相关文章

  1. Java Filter过滤器(拦截路径的配置+拦截方式的配置+生命周期+多个过滤器的先后执行顺序)

    Java Filter过滤器+Listen监听器 啥是过滤器 顾名思义即过滤掉一些东西,比如我们经历的高考中考都是过滤器,他过滤掉一些在学习这一方面不是很好的人,而那些成绩好的人则升入高中,大学. 但 ...

  2. STM8S---IO复用配置(STVP方式)

    1 说明 STM8S的IO复用用程序代码配置起来比較麻烦.通常是操作flash来操作option byte字节.配置寄存器更加麻烦,能够使用STM 标准外设驱动库来设置. 本文使用一种界面配置的方式来 ...

  3. Web API 实现JSONP或者安装配置Cors跨域

    前言 照理来说本节也应该讲Web API原理,目前已经探讨完了比较底层的Web API消息处理管道以及Web Host寄宿管道,接下来应该要触及控制器.Action方法,以及过滤器.模型绑定等等,想想 ...

  4. 离线环境下使用二进制方式安装配置Kubernetes集群

    本文环境 Redhat Linux 7.3,操作系统采用的最小安装方式. Kubernetes的版本为 V1.10. Docker版本为18.03.1-ce. etcd 版本为 V3.3.8. 1. ...

  5. servlet 3 通过编程的方式来配置ServletContext

    你是否再为配置文件web.xml容易出错而烦恼?是否为web.xml文件存放位置而不知所措?是否为web.xml为什么要这样配?怎么才能更好的配置web.xml而烦恼?那么一种新的方式出现了: spr ...

  6. spring 事务管理方式及配置

    1.Spring声明式事务配置的五种方式 前段时间对Spring的事务配置做了比较深入的研究,在此之前对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识.通过这次的学习发觉Spring的 ...

  7. 通过配置的方式Autofac 《第三篇》

    一.基本配置 1.通过配置的方式使用Autofac <?xml version="1.0"?> <configuration> <configSect ...

  8. 关于SpringAOP的XML方式的配置

    AOP(XML)[理解][应用][重点] 1.AOP基础实例 A.导入jar包 核心包(4个)         日志(2个)             AOP(4个) Spring进行AOP开发(1个) ...

  9. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

  10. Oracle BEQ方式连接配置

    Oracle BEQ方式连接配置 服务端和客户端在同一台机器上,可以使用BEQ连接,BEQ连接可以理解为进程间直接通信,不需要走网络监听,性能更高. 可以参考MOS:How To Connect Us ...

随机推荐

  1. 搭建一个简易的IPv6网络测试环境

    背景 近期一个项目要求产品在IPv6网络环境部署,在此之前所有的项目网络环境都是IPv4,为了验证产品网络适配能力,需要搭建一套IPv6的网络测试环境,网上搜了很多教程,也在某东找了很多路由器,对于如 ...

  2. [ABC263B] Ancestor

    Problem Statement There are $N$ people, called Person $1$, Person $2$, $\ldots$, Person $N$. The par ...

  3. 基于.NET Core + Quartz.NET+ Vue + IView开箱即用的定时任务UI

    前言 定时任务调度应该是平时业务开发中比较常见的需求,比如说微信文章定时发布.定时更新某一个业务状态.定时删除一些冗余数据等等.今天给大家推荐一个基于.NET Core + Quartz.NET + ...

  4. Python+Selenium+Webdriver+unittest 实现登录126邮箱

    第一版:登录 #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webd ...

  5. 15、string

    1.string是什么? Go中的字符串是一个字节的切片,可以通过将其内容封装起在""中来创建字符串.Go中的的字符串是Unicode兼容的并且是UTF-8编码的. 2.strin ...

  6. flask的cookie和session会话保持

    Cookie 获取请求cookie 通过请求对象中的cookies属性可以获取cookie. 实例: from flask import Flask, request @app.route(" ...

  7. STM32CubeMX教程1 工程建立

    1.准备材料 开发板(STM32F407G-DISC1) ST-LINK/V2驱动 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) 2 ...

  8. Python——第二章:字符串操作——索引和切片

    索引: 按照位置提取元素 可以采用索引的方式来提取某一个字符(文字) s = "我叫周杰伦" print(s[3]) #程序员都是从0开始数,这里的3代表第4位,也就是" ...

  9. zabbix常用监控项

    https://blog.csdn.net/xkjcf/article/details/78559273?locationNum=10&fps=1 agent.ping  #agent是否在线 ...

  10. zookeeper源码(05)数据存储

    本文详细分析一下zookeeper的数据存储. ZKDatabase 维护zookeeper服务器内存数据库,包括session.dataTree和committedlog数据,从磁盘读取日志和快照后 ...