标签:抽象 start success reference 耦合 doc ati out registry
docker pull zookeeper
docker run --name zk01 -p 2181:2181 --restart always -d 2e30cac00aca
表明zookeeper已成功启动
客户端(consumer)配置:
启动类
@SpringBootApplication
public class ConsumerManagerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerManagerApplication.class, args);
}
}
controller
@RestController
public class ManagerController {
@Reference
ManagerService managerService;
@RequestMapping("/hello")
public String hello() {
return managerService.hello();
}
}
service(只需要跟服务类的接口一致就行,包名也要一致)
public interface ManagerService {
public String hello();
}
application.properties
dubbo.application.name=consumer-manager
dubbo.registry.address=zookeeper://192.168.0.106:2181
server.port=8081
服务端(provider)配置:
启动类
@SpringBootApplication
public class ProviderManagerApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderManagerApplication.class, args);
}
}
service接口和实现类
public interface ManagerService {
public String hello();
}
@Service
public class ManagerServiceImpl implements ManagerService {
@Override
public String hello() {
System.out.println("客户端请求进来了!");
return "xixi success !!!";
}
}
application.properties
dubbo.application.name=provider-manager
dubbo.registry.address=zookeeper://192.168.0.106:2181
dubbo.scan.base-packages=com.hourui
浏览器访问:
标签:抽象 start success reference 耦合 doc ati out registry
原文地址:https://www.cnblogs.com/liuyi13535496566/p/12343208.html