public interface HelloService { String sayHello(String name); } public class HelloServiceImpl implements HelloService { public String sayHello(String name) { return "Hello, " + name; } } <dubbo:application name="hello-service-provider" /> <dubbo:registry address="zookeeper://localhost:2181" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="com.example.HelloService" ref="helloService" /> <bean id="helloService" class="com.example.HelloServiceImpl" /> public class Provider { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-provider.xml"); context.start(); System.in.read(); } } public class Consumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-consumer.xml"); HelloService helloService = context.getBean("helloService", HelloService.class); String result = helloService.sayHello("Dubbo"); System.out.println(result); } }


上一篇:
下一篇:
切换中文