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