搭建Eureka服务注册中心
前面说过eureka是c/s模式的 server服务端就是服务注册中心,其他的都是client客户端,服务端用来管理所有服务,客户端通过注册中心,来调用具体的服务;
我们先来搭建下服务端,也就是服务注册中心;
新建 module microservice-eureka-server-2001
4.0.0
com.java1234.springcloud
microservice
0.0.1-SNAPSHOT
microservice-eureka-server-2001
org.springframework.cloud
spring-cloud-starter-eureka-server
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
主要是加入eureka-server依赖;
application.yml配置:server:
port: 2001
context-path: /
eureka:
instance:
hostname: localhost #eureka注册中心实例名称
client:
register-with-eureka: false #false 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己。
fetch-registry: false #false 由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与Eureka注册中心交互的地址,查询服务和注册服务用到
启动类:package com.java1234;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication_2001 {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication_2001.class, args);
}
}
主要是要加入下@EnableEurekaServer
测试:
出现这个 就说明OK;