赞
踩
consumer-server
和provider-server
- <!-- nacos服务注册发现 -->
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
- <version>2.2.2.RELEASE</version>
- </dependency>
- <!-- dubbo依赖 -->
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-nacos</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>com.fan</groupId>
- <artifactId>provider-server</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </dependency>
- public interface HelloService {
- String sayHello(String name);
- }
- public class HelloServiceimpl implements HelloService{
- @Override
- public String sayHello(String name) {
- return "张三"+name;
- }
- }
- server.port=8080
- spring.application.name=dubbo-demo-provider
- spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
- dubbo.protocol.name=dubbo
- dubbo.protocol.port=-1
- dubbo.registry.address=nacos://127.0.0.1:8848
- dubbo.application.name=dubbo-demo-provider
- dubbo.consumer.check=false
- <!-- nacos服务注册发现 -->
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
- <version>2.2.2.RELEASE</version>
- </dependency>
- <!-- dubbo依赖 -->
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-nacos</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>com.fan</groupId>
- <artifactId>provider-server</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>com.fan</groupId>
- <artifactId>provider-server</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </dependency>
- @RestController
- public class MainController
- {
- @DubboReference
- private HelloService helloService;
- @GetMapping("/")
- public String index()
- {
- return helloService.sayHello("dubbo");
- }
- }
- server.port=9090
- spring.application.name=dubbo-demo-consumer
- spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
- dubbo.protocol.name=dubbo
- dubbo.protocol.port=-1
- dubbo.registry.address=nacos://127.0.0.1:8848
- dubbo.application.name=dubbo-demo-consumer
- dubbo.consumer.check=false
nacos启动后启动项目
然后访问9090端口发现报错
在provider-server启动类加上@EnableDubbo 重新启动查看 还是报错检查发现HelloServiceimpl中忘记了@DubboService 加上重新启动测试
完成
- server.port=8080 #应用端口
- spring.application.name=dubbo-demo-provider #服务名称
- spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 #将服务注册到nacos
- dubbo.protocol.name=dubbo #使用协议
- dubbo.protocol.port=-1 #调用协议地址
- dubbo.registry.address=nacos://127.0.0.1:8848 #dubbo注册中心
- dubbo.application.name=dubbo-demo-provider #dubbo服务名称
- dubbo.consumer.check=false #dubbo启动时检查
前面使用了spring-cloud-starter-alibaba-nacos-discovery的jar
也可以使用。流程也是一样的
- <!--dubbo和nacos-->
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.7.8</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-nacos</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- <version>1.1.4</version>
- </dependency>
dubbo.protocol.port=20881
这个端口有一样的应用会启动不起来
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。