Loading

注册中心Eureka

https://gitee.com/hslxy/spring-cloud-learning
注册中心 Eureka

服务端

pom

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

application.yml

server:
  port: 8001

spring:
  application:
    name: eureka-server
eureka:
  instance:
    hostname: localhost 
  client:
    fetch-registry: false 
    register-with-eureka: false 
  server:
    enable-self-preservation: false 

主函数添加注解@EnableEurekaServer

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

客户端

pom

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

application.yml

server:
  port: 8101 
spring:
  application:
    name: eureka-client 
eureka:
  client:
    register-with-eureka: true 
    fetch-registry: true 
    service-url:
      defaultZone: http://localhost:8002/eureka/,http://localhost:8003/eureka/

主函数添加@EnableDiscoveryClient

@EnableDiscoveryClient
@SpringBootApplication
public class EurekaClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaClientApplication.class, args);
    }
}
posted @ 2022-12-01 19:08  要努力哇  阅读(36)  评论(0)    收藏  举报