eclipse启动2个EurekaClient 实例

1、创建EurekaService 

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

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

application.yml

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url: 
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      
spring:
  application:
    name: eurka-server

项目结构:

eclipse启动2个EurekaClient 实例_第1张图片

2、新建spring boot项目 添加@EnableEurekaClient

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

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

application.yml

server:
  port: 8762

spring:
  application:
    name: spring-cloud-front
eureka:
  instance:
    instance-id: spring-cloud-front1    #id一定要与 application-two.yml 中id不同,不然2个实例会被覆盖
    appname: ${spring.application.name}
  client: 
    service-url: 
      defaultZone: http://localhost:8761/eureka/

 

application-two.yml

server:
  port: 8765

spring:
  application:
    name: spring-cloud-front
eureka:
  instance:
    instance-id: spring-cloud-front2
    appname: ${spring.application.name}
  client: 
    service-url: 
      defaultZone: http://127.0.0.1:8761/eureka/

项目结构:
eclipse启动2个EurekaClient 实例_第2张图片

3、先运行EurekaService  App  : Run As > java application

4、运行  front  App  : Run As >  java application  默认启动application.yml 配置

5、再启动一个EurekaClient  : Run As > run configurations > 修改Arguments  --spring.profiles.active=two  运行

eclipse启动2个EurekaClient 实例_第3张图片

 

6、eclipse 2个EurekaClient启动成功。 输入地址 http://localhost:8761/

eclipse启动2个EurekaClient 实例_第4张图片

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(spring,cloud)