一.配置application.yml文件
# 本配置为eureka单机配置
spring:
application:
name: psd-eureka
# 端口号
server:
port: 8000
eureka:
instance:
hostname: localhost
client:
# eureka.client.fetch-registry: 表示是否从 Eureka Server 获取注册信息,默认为true。如果这是一个单点的 Eureka Server,不需要同步其他节点的数据,设为false
fetch-registry: false
# eureka.client.register-with-eureka: 表示是否将自己注册到 Eureka Server, 默认为true。由于当前应用就是 Eureka Server, 因此设为 false
register-with-eureka: false
# 设置 Eureka Server 所在的地址,查询服务和注册服务都需要依赖这个地址
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
二.创建服务启动类:
package com.lg.psd;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* 1.EnableEurekaServer:让本应用成为一个Eureka服务
* 2.pom 文件中对应到 spring-cloud-starter-netflix-eureka-server
*/
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
以上,完成单机版的Eureka配置,控制台运行启动类,访问对应端口 http://localhost:8080(具体ip:端口号就看你的实际情况及配置),成功访问则完成配置(如下图)。
附上Gitee的源码: