zoukankan      html  css  js  c++  java
  • 使用JavaConfig方式配置dubbox

    为了迎合Spring的所有配置方式,增加了无XML配置实现,在此不对两种方式的优劣做比较,请根据项目的使用习惯做出合理选择。

    1. 模块描述

    实现Spring的JavaConfig配置方式,使用 Main.main(args) (需传参javaconfig设置使用JavaConfigContainer) 启动时可直接扫描 dubbo.spring.javaconfig包下的所有的Spring配置类

    2. 使用示例

    使用示例在dubbo-demo/dubbo-demo-consumer模块中,相关配置方式参考 注解配置

    2.1 代码解释

    • dubbo-demo-consumer/../DubboDemoConsumerConfig 等同于 dubbo-demo-consumer/../dubbo-demo-consumer.xml
    • dubbo-demo-consumer/../DubboDemoActionConfig 等同于 dubbo-demo-consumer/../dubbo-demo-action.xml
    • dubbo-demo-consumer/../DemoJavaConfigAction 等同于 dubbo-demo-consumer/../DemoAction
    • dubbo-demo-consumer/../DemoJavaConfigConsumer 以JavaConfig方式启动示例程序

    2.2 示例演示

    1. 运行dubbo-demo-provider/../DemoProvider
    2. 运行dubbo-demo-consumer/../DemoJavaConfigConsumer
    3. 查看console输出

    3. 无XML配置

    将XML配置方式转换为JavaConfig配置,demo中未涉及到的配置类,请参照 API配置 实现

    @Configuration
    public class DubboDemoConsumerConfig {
    
        public static final String APPLICATION_NAME = "consumer-of-helloworld-app";
    
        public static final String REGISTRY_ADDRESS = "zookeeper://127.0.0.1:2181";
    
        public static final String ANNOTATION_PACKAGE = "com.alibaba.dubbo.demo.consumer";
    
        @Bean
        public ApplicationConfig applicationConfig() {
            ApplicationConfig applicationConfig = new ApplicationConfig();
            applicationConfig.setName(APPLICATION_NAME);
            return applicationConfig;
        }
    
        @Bean
        public RegistryConfig registryConfig() {
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress(REGISTRY_ADDRESS);
            return registryConfig;
        }
    
        @Bean
        public AnnotationBean annotationBean() {
            AnnotationBean annotationBean = new AnnotationBean();
            annotationBean.setPackage(ANNOTATION_PACKAGE);
            return annotationBean;
        }
    }
  • 相关阅读:
    Guava入门第四章(Objects)
    Guava入门第三章(Preconditions)
    Guava入门第二章(Splitter)
    Guava入门第一章(Joiner)
    Docker入门第六章
    Docker遇到的问题
    Docker命令图
    2016-08-26-Java比较器的使用
    2017-10-6-MyBatis配置简述
    2017-9-17-Java Exception小结
  • 原文地址:https://www.cnblogs.com/devotion/p/5199398.html
Copyright © 2011-2022 走看看