Eureka客户端-服务提供者

1、pom.xml

 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
 </dependency>

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <!--客户端只有当我们有了这个依赖之后,才能有那些状态页面的查看,否则会报ErrorPage-->
 </dependency>

2、application.yml

spring:
  application:
    name: eureka-client-provider
#   设置我们的服务名称
server:
  port: 8601
#  servlet:
#    context-path: /jdbc
  #   设置服务访问地址以/jdbc开头
eureka:
  instance:
    prefer-ip-address: true
#    status-page-url-path: /actuator/info
#    health-check-url-path: /actuator/health
#    这两个都是默认的地址
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
    healthcheck:
      enabled: true
    #健康检查,eureka实例注册到eureka服务器上是以一个实例为单位的,eureka是根据客户端实例的心跳来确定客户端是否启动,也就是说
    #即使我们的实例的一部分服务宕掉,我们的实例整体没有宕掉的时候,请求还是会分发到此实例中,开启健康检查之后,就会将服务的状态
    #发送到应用程序

3、要提供的服务

@RestController
public class ServiceProvider {
    @Value("${server.port}")
    private String port;
    @RequestMapping("/getUUid")
    public String getUUid(Integer i){
        UUID uuid = UUID.randomUUID();
        String s = i + "==="+uuid.toString();
        return s;
    }
    @RequestMapping("/getServerPort")
    public String getServerPort(){
        return port;
    }
}

4、启动类

@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaClientProviderApplication.class, args);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42152604/article/details/84583045
今日推荐