dubbo.application.name=example-app
dubbo.registry.address=zookeeper://127.0.0.1:2181
public interface ExampleService {
String sayHello(String name);
}
public class ExampleServiceImpl implements ExampleService {
@Override
public String sayHello(String name) {
return "Hello, " + name;
}
}
public class ExampleConsumer {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-dubbo.xml");
ExampleService exampleService = (ExampleService) context.getBean("exampleService");
String result = exampleService.sayHello("World");
System.out.println(result);
}
}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="example-app-consumer"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:reference id="exampleService" interface="com.example.ExampleService"/>
</beans>