public interface HelloService {
String sayHello(String name);
}
public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
return "Hello, " + name + "!";
}
}
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:service interface="com.example.HelloService" ref="helloService" />
<dubbo:reference interface="com.example.HelloService" id="helloService" />
public class Provider {
public static void main(String[] args) {
com.alibaba.dubbo.container.Main.main(args);
}
}
public class Consumer {
public static void main(String[] args) {
HelloService helloService = (HelloService) com.alibaba.dubbo.container.Main
.getSpringContext().getBean("helloService");
String result = helloService.sayHello("Dubbo");
System.out.println(result);
}
}