笔记:Eureka客户端注册服务

项目基佬网址:https://github.com/woshiyinweijian/SpringCloudTest

新建一个项目:eureka-provider,主要依赖:

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

配置文件:

spring:
  application:
    name: eureka-provider

server:
    port: 8081

eureka:
  instance:
    hostname: 127.0.0.1 #对应页面上的DS Replicas,服务端的域名
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8080/eureka/ # 服务的注册网址

启动类加入注解:@EnableEurekaClient

@SpringBootApplication
@EnableEurekaClient
public class EurekaProviderApplication {

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

同时创建一个Controller:ProviderController.java

package cn.ywj.eurekaprovider;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProviderController {

    @RequestMapping("/test")
    public Object test(){
        return 0;
    }
}

OK

先启动eureka项目,再启动当前项目eureka-provider,访问:http://127.0.0.1:8080/

效果如下图,可以看到有一个实例EUREKA-PROVIDER已注册服务了

OK,停笔休息。

猜你喜欢

转载自blog.csdn.net/u013845177/article/details/82809496