Skip to content

Commit

Permalink
Upgrade annotation demo
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Dec 12, 2017
1 parent d528433 commit 05461a4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package com.alibaba.dubbo.examples.annotation;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.alibaba.dubbo.examples.annotation.action.AnnotationAction;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* CallbackConsumer
Expand All @@ -27,13 +31,20 @@
public class AnnotationConsumer {

public static void main(String[] args) throws Exception {
String config = AnnotationConsumer.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
context.start();
final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
String hello = annotationAction.doSayHello("world");
System.out.println("result :" + hello);
System.in.read();
}

@Configuration
@EnableDubbo(scanBasePackages = "com.alibaba.dubbo.examples.annotation.action", multipleConfig = true)
@PropertySource("classpath:/com/alibaba/dubbo/examples/annotation/dubbo-consumer.properties")
@ComponentScan(value = {"com.alibaba.dubbo.examples.annotation.action"})
static public class ConsumerConfiguration {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
*/
package com.alibaba.dubbo.examples.annotation;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* MergeProvider
Expand All @@ -25,10 +31,22 @@
public class AnnotationProvider {

public static void main(String[] args) throws Exception {
String config = AnnotationProvider.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();
System.in.read();
}

@Configuration
@EnableDubbo(scanBasePackages = "com.alibaba.dubbo.examples.annotation.impl", multipleConfig = true)
@PropertySource("classpath:/com/alibaba/dubbo/examples/annotation/dubbo-provider.properties")
// @ComponentScan(value = {"com.alibaba.dubbo.examples.annotation.impl"})
static public class ProviderConfiguration {
@Bean
public ProviderConfig providerConfig() {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setTimeout(1000);
return providerConfig;
}
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#<dubbo:application name="annotation-consumer"/>
dubbo.application.application-id.name=annotation-consumer
#<dubbo:registry id="registry-id" address="multicast://224.5.6.7:1234"/>
dubbo.registry.registry-id.address=zookeeper://127.0.0.1:2181
dubbo.consumer.consumer-id.timeout=3000
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#<dubbo:application id="application-id" name="dubbo-annotation-provider"/>
dubbo.application.application-id.name=xxx
#<dubbo:registry id="registry-id" address="multicast://224.5.6.7:1234"/>
dubbo.registry.registry-id.address=zookeeper://127.0.0.1:2181
#<dubbo:protocol id="protocol-id" name="dubbo" port="12345"/>
dubbo.protocol.protocol-id.name=dubbo
dubbo.protocol.protocol-id.port=20883

0 comments on commit 05461a4

Please sign in to comment.