<dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-all</artifactId> <version>2.7.8</version> </dependency> public interface UserService { User getUserById(int id); } @Service public class UserServiceImpl implements UserService { public User getUserById(int id) { } } properties dubbo.application.name=example-app dubbo.registry.address=zookeeper://localhost:2181 dubbo.protocol.name=dubbo dubbo.protocol.port=12345 public class SampleClient { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:dubbo.xml"); UserService userService = (UserService) context.getBean("userService"); User user = userService.getUserById(1); System.out.println(user.getName()); } } <dubbo:reference id="userService" interface="com.example.UserService" />


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