eureka客户端
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>eurekaClient</artifactId>
<groupId>com.lv</groupId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<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-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>eurekaClient</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置2个 启动参数配置 --spring.profiles.active=node1
application-node1.yml
server:
port: 8001
spring:
application:
name: eurekaClient
profiles: node1
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7000/eureka/
application-node2.yml
server:
port: 8002
spring:
application:
name: eurekaClient
profiles: node2
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7000/eureka/
JarApp
package com.lv;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* Created by lvyanghui
* 2019/2/27 10:52
*/
@EnableEurekaClient
@SpringBootApplication
public class JarApp {
public static void main(String[] args) {
SpringApplication.run(JarApp.class,args);
}
}
HelloController
package com.lv.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by lvyanghui
* 2019/2/27 16:40
*/
@RestController
@RequestMapping("/test")
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "Hello World";
}
}