1、引用相关依赖
<!--eureka-server服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
2、配置application.yml文件
server:
port: 7001
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
#设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址。
3、编写启动类文件,开启eureka注解(@EnableEurekaServer)
@SpringBootApplication
@EnableEurekaServer // EurekaServer服务器端启动类,接受其它微服务注册进来
public class EurekaServerSpringApplication
{
public static void main(String[] args)
{
SpringApplication.run(EurekaServer7001_App.class, args);
}
}
4、访问页面(no instances available:没有服务被发现,因为还没有服务注册进来)