Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring javaconfig container #5

Merged
merged 3 commits into from
Nov 14, 2014
Merged

spring javaconfig container #5

merged 3 commits into from
Nov 14, 2014

Conversation

majinkai
Copy link

1. 模块描述

实现Spring的JavaConfig配置方式,使用 Main.main(args) (需传参javaconfig设置使用JavaConfigContainer) 启动时可直接扫描 bubbo.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配置方式转换为Java类配置,未涉及到的配置,请参照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;
    }
}

li-shen added a commit that referenced this pull request Nov 14, 2014
@li-shen li-shen merged commit 7b29f97 into dangdangdotcom:master Nov 14, 2014
@majinkai majinkai deleted the feature/spring-javaconfig-container branch November 16, 2014 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants