标签:url org 官方 oid map pre mapping blog pom
7.配置服务提供者(生产者)
7.1.配置resources/application.yml.
值eureka.client.service-url(或serviceUrl).defaultZone是配置将服务注册到那个注册中心,server.port是自己服务占用的端口,spring。application.name是服务在注册中心的名字,需要是唯一的,见7.2下图:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8888/eureka/
server:
port: 8889
spring:
application:
name: server-provider
7.2.在启动入口类上加入注解@EnableEurekaClient,然后启动,刷新localhost:8888,可以看到这个服务。
7.3.用postman测试这个服务,在启动类上加注解@RestController(sprig中注解constroller与responsebody的合体),测个返回hello world!的接口(一个服务)。EurekaProviderApplication.java文件
package com.springcloud.eurekaprovider; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @EnableEurekaClient @RestController public class EurekaProviderApplication { public static void main(String[] args) { SpringApplication.run(EurekaProviderApplication.class, args); } @RequestMapping("/hello") public String home() { return "hello world! "; } }
postman选择get/post请求,然后输入localhost:8889/hello发送请求能看到hello world!就说明服务时可用的
8.陪服务的消费者
8.1.打开pom文件,添加几个新的依赖,我看到有说spring-cloud-starter-eureka这个包被官方放弃了,和spring-cloud-starter-netflix-eureka-server推荐用作个包,我这里都加进来了,参考的文章是这样的,等下成功了,我去掉试一下。(参考文章:https://blog.csdn.net/zhou199252/article/details/80745151)
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> <version>1.4.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
8.2.配置resources/application.yml.
springcloud学习03-spring cloud eureka(下)
标签:url org 官方 oid map pre mapping blog pom
原文地址:https://www.cnblogs.com/wang-liang-blogs/p/12072423.html