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


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