一、eureka 服务端程序配置
1、引入依赖 pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>3.1.4</version>
</dependency>
2、设置启动类
//启动类添加注解:@EnableEurekaServer
@EnableEurekaServer
@SpringBootApplication
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}
3、配置eureka属性 application.yml
spring:
application:
name: eurekaserver
server:
port: 10086
eureka:
instance:
hostname: localhost
client:
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
4、进入eureka服务页面
# 成功注册服务端--注册自己本身 eureka-server
二、eureka 客户端程序配置
1、引入依赖 pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>3.1.4</version>
</dependency>
</dependencies>
2、设置启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableEurekaClient
@SpringBootApplication
public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
3、配置eureka属性 application.yml
spring:
application:
name: eureka-client
server:
port: 10010
eureka:
instance:
hostname: localhost
client:
# 注册到指定的服务器地址中
service-url:
defaultZone: http://127.0.0.1:10086/eureka/
4、进入eureka服务页面
# 成功注册客户端 eureka-client