<dubbo:application name="dubbo-demo-provider" /> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="com.example.service.UserService" ref="userService" /> <bean id="userService" class="com.example.service.UserServiceImpl" /> package com.example.service; public class UserServiceImpl implements UserService { @Override public String getUserInfo(String userId) { return "User ID: " + userId; } } <dubbo:application name="dubbo-demo-consumer" /> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <dubbo:reference id="userService" interface="com.example.service.UserService" /> package com.example.consumer; import com.example.service.UserService; import org.springframework.context.support.ClassPathXmlApplicationContext; public class UserServiceConsumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-consumer.xml"); UserService userService = (UserService) context.getBean("userService"); String userInfo = userService.getUserInfo("123"); System.out.println(userInfo); } }


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