1、創(chuàng)建一個springBoot項目
2、在springBoot項目中添加SpringCloud依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
3、在springBoot項目中創(chuàng)新建一個子模塊eureka-server:
4、搭建Eureka
- 添加依賴:在新建一個子模塊的pom.xml中添加依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>3.1.3</version>
<type>pom</type>
</dependency>
- 創(chuàng)建配置文件:在resources文件下創(chuàng)建一個名為
application.yml
(或application.properties
)的配置文件,并為Eureka Server配置必要的屬性。以下是一個基本的示例配置:
spring:
application:
name: eurekaServer
server:
port: 8761
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka/
1、第一個配置是為Eureka命名
2、第二個配置是設(shè)置Eureka的端口
3、第三個配置是將Eureka自己也看成是一個服務(wù),將自己注冊到Eureka中
- 創(chuàng)建啟動類名為EurekaApplication:創(chuàng)建一個啟動類并標(biāo)注
@EnableEurekaServer
注解,以啟用Eureka Server。示例代碼如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
-
啟動:運行啟動類
-
驗證:通過訪問
http://localhost:8761
(或自定義的端口)。應(yīng)該能夠看到Eureka Server的管理控制臺,并且如果沒有其他注冊的服務(wù),注冊中心應(yīng)該有一個eurekaserver。文章來源:http://www.zghlxwxcb.cn/news/detail-619113.html
這樣,就成功地搭建了一個簡單的Eureka Server。接下來,可以根據(jù)需要搭建Eureka Client,并將其他微服務(wù)注冊到Eureka Server上。文章來源地址http://www.zghlxwxcb.cn/news/detail-619113.html
到了這里,關(guān)于springCloud Eureka注冊中心配置詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!