首页技术教程 正文

springCloud之Eureka服务器

2024-03-15 19 0条评论
选择Cloud Discovery下面Eureka有两个选项,,Eureka Server和Eureka Discovery。一个是Eureka Server,一个是Eureka Client。,查看生成的pom,区别就在引入的jar包不同,一个是spring- cloud-starter-netflix-eureka-client,一个是spring-cloud-starter-netflix-eureka-server。netflix的starter几经修改,变成了现在的样子。,一、配置文件中配置(以下两种方式根据自己需求复制即可),(1) application.yml,(2)application.properties,二、在启动类上添加@EnableEurekaServer,三、在pom.xml文件中配置(通过idea中选择Spring Initializr中Cloud Discovery中Eureka Server创建的项目忽略此步骤),4、启动项目,输入localhost:1111看一下效果,见到此页面即代表Eureka Server创建成功,

1.创建Eureka Server

使用idea通过Spring Initializr创建,选择Web和Cloud Discovery里面的Eureka Server

选择Cloud Discovery下面Eureka有两个选项,

Eureka Server和Eureka Discovery。一个是Eureka Server,一个是Eureka Client。

查看生成的pom,区别就在引入的jar包不同,一个是spring-cloud-starter-netflix-eureka-client,一个是spring-cloud-starter-netflix-eureka-server。netflix的starter几经修改,变成了现在的样子。

一、配置文件中配置(以下两种方式根据自己需求复制即可)

(1)application.yml

server: #指定服务端口 port: 1111 eureka: #server一定程度上也是client,互为client, client: #由于自己就是 服务器,不需要注册到自己 register-with-eureka: false #由于自己就是服务器,不需要从服务器获取注册信息 fetch-registry: false #服务地址 service-url: defaultZone: http://localhost:${server.port}/eureka/

(2)application.properties

#指定服务端口server.port=1111#由于自己就是服务器,不需要注册到自己eureka.client.register-with-eureka=false#由于自己就是服务器,不需要从服务器获取注册信息eureka.client.fetch-registry=false#服务地址eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

二、在启动类上添加@EnableEurekaServer

@EnableEurekaServer//eureka server需要添加的代码@SpringBootApplicationpublic class SpringcloudServerApplication { public static void main(String[] args) { SpringApplication.run(SpringcloudServerApplication.class, args); }}

三、在pom.xml文件中配置(通过idea中选择Spring Initializr中Cloud Discovery中Eureka Server创建的项目忽略此步骤)

org.springframework.cloud spring-cloud-starter-netflix-eureka-server

4、启动项目,输入localhost:1111看一下效果

见到此页面即代表Eureka Server创建成功


文章版权及转载声明

本文作者:亿网 网址:https://edns.com/ask/post/25544.html 发布于 2024-03-15
文章转载或复制请以超链接形式并注明出处。