国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot整合eureka簡記

這篇具有很好參考價值的文章主要介紹了SpringBoot整合eureka簡記。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

Eureka是一個服務(wù)治理組件,它主要包括服務(wù)注冊和服務(wù)發(fā)現(xiàn),主要用來搭建服務(wù)注冊中心。

Eureka 是一個基于 REST 的服務(wù),用來定位服務(wù),進(jìn)行中間層服務(wù)器的負(fù)載均衡和故障轉(zhuǎn)移;

Eureka是Netflix 公司開發(fā)的,Spring Cloud發(fā)現(xiàn)eureka很好使,因此將eureka封裝到自己的模塊中。

springboot集成eureka,微服務(wù),eureka,spring boot,java

?文章來源地址http://www.zghlxwxcb.cn/news/detail-568601.html

1、要使用eureka,首先要創(chuàng)建一個服務(wù),eureka本身也是一個微服務(wù)

引入springcloud和eureka-server

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
        <version>1.4.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>

</dependencyManagement>

這個地方有一個坑,我折騰了半天才啟動成功。springboot和springcloud是有對應(yīng)關(guān)系的

SpringCloud版本 SpringBoot版本
2021.0.1-SNAPSHOT Spring Boot >=2.6.4-SNAPSHOT and <2.7.0-M1
2021.0.0 Spring Boot >=2.6.1 and <2.6.4-SNAPSHOT
2021.0.0-RC1 Spring Boot >=2.6.0-RC1 and <2.6.1
2021.0.0-M3 Spring Boot >=2.6.0-M3 and <2.6.0-RC1
2021.0.0-M1 Spring Boot >=2.6.0-M1 and <2.6.0-M3
2020.0.5 Spring Boot >=2.4.0.M1 and <2.6.0-M1
Hoxton.SR12 Spring Boot >=2.2.0.RELEASE and <2.4.0.M1
Hoxton.BUILD-SNAPSHOT Spring Boot >=2.2.0.BUILD-SNAPSHOT
Hoxton.M2 Spring Boot >=2.2.0.M4 and <=2.2.0.M5
Greenwich.BUILD-SNAPSHO Spring Boot >=2.1.9.BUILD-SNAPSHOT and <2.2.0.M4
Greenwich.SR2 Spring Boot >=2.1.0.RELEASE and <2.1.9.BUILD-SNAPSHOT
Greenwich.M1 Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE
Finchley.BUILD-SNAPSHOT Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3
Finchley.SR4 Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT
Finchley.RC2 Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE
?Finchley.RC1 ?Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE
Finchley.M9 Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE
Finchley.M7 Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2
Finchley.M6 Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1
Finchley.M5 Spring Boot >=2.0.0.M7 and <=2.0.0.M7
Finchley.M4 Spring Boot >=2.0.0.M6 and <=2.0.0.M6
Finchley.M3 Spring Boot >=2.0.0.M5 and <=2.0.0.M5
Finchley.M2 Spring Boot >=2.0.0.M3 and <2.0.0.M5
Edgware.SR5 1.5.20.RELEASE
Edgware.SR5 1.5.16.RELEASE
Edgware.RELEASE 1.5.9.RELEASE
Dalston.RC1 1.5.2.RELEASE

為eureka服務(wù)增加注解說明

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {

        SpringApplication.run(EurekaApplication.class, args);
    }
}

為eureka服務(wù)增加配置

server:

  port: 9000
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

?

這里我使用9000端口作為eureka的服務(wù)端口?

啟動后可以看到eureka服務(wù)的展示頁面,可以看到,這時候是沒有服務(wù)注冊進(jìn)來的。

springboot集成eureka,微服務(wù),eureka,spring boot,java

?2、創(chuàng)建微服務(wù)注冊到eureka服務(wù)

pom文件,簡化版,其他springcloud和springboot的引用和eureka相同

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
</dependencies>

服務(wù)啟動類

@SpringBootApplication
@EnableEurekaClient
public class OrderApplication {


    public static void main(String[] args) {

        SpringApplication.run(OrderApplication.class, args);
    }
}

配置文件

server:

  port: 1001
eureka:
  instance:
    prefer-ip-address: true

    hostname: localhost
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:9000/eureka/
spring:
  application:
    name: orderservice

這里我使用1001作為第一個微服務(wù)?端口號,下邊使用1002創(chuàng)建另一個微服務(wù),配置同理

啟動后

springboot集成eureka,微服務(wù),eureka,spring boot,java

?可以看到,兩個服務(wù)均已經(jīng)成功注冊到eureka服務(wù)。

3、創(chuàng)建另一個微服務(wù)去調(diào)用已經(jīng)注冊進(jìn)去的服務(wù),配置相同,這里只截圖調(diào)用相關(guān)代碼

@Autowired
RestTemplate restTemplate;

@RequestMapping("indexClient.do")

public @ResponseBody String indexClient() {

     return restTemplate.getForEntity("http://orderservice/index.do", String.class).getBody();

}

使用的是RestTemplate,RestTemplate簡化了發(fā)起 HTTP 請求以及處理響應(yīng)的過程,并且支持 REST,類似于自己創(chuàng)建的http請求類。

這里有個小坑,如果clean服務(wù)后配置文件application.yml有可能會被從target中刪除,這里需要手動復(fù)制到target中,不然會啟動失敗,而且配置的server端口不生效,謹(jǐn)記。

為了不至于學(xué)習(xí)資料丟失,代碼已經(jīng)上傳至以下地址:

(3條消息) springboot整合eureka源代碼,學(xué)習(xí)資料-Java文檔類資源-CSDN文庫

?

到了這里,關(guān)于SpringBoot整合eureka簡記的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 二十、微服務(wù)之-Spring Cloud使用、打包、啟動與整合springboot

    二十、微服務(wù)之-Spring Cloud使用、打包、啟動與整合springboot

    根據(jù) Spring Cloud 的官方網(wǎng)站,Spring Cloud 為開發(fā)人員提供了一些快速構(gòu)建分布式系統(tǒng)常見模式的工具(例如 配置管理、服務(wù)發(fā)現(xiàn)、斷路器、智能路由、領(lǐng)導(dǎo)選舉、分布式會話、集群狀態(tài) )。 安裝 IntelliJ IDEA:從 JetBrains 官方網(wǎng)站下載適用于您操作系統(tǒng)的 IntelliJ IDEA 版本,并按照

    2024年04月29日
    瀏覽(14)
  • springboot整合eureka、config搭建注冊中心和配置中心

    springboot整合eureka、config搭建注冊中心和配置中心

    這篇文章詳細(xì)介紹怎么通過eureka和config分別搭建一個注冊中心和配置中心的服務(wù)。 目錄 一 、springboot整合eureka搭建注冊中心 二、springboot整合config搭建配置中心 三、從配置中心拉取配置 1、在IntelliJ IDEA中創(chuàng)建一個springboot項(xiàng)目,并命名為eureka 2、修改pom.xml,添加eureka-server的依

    2024年02月16日
    瀏覽(33)
  • Springboot3.X整合Dubbo3.XSpringCloudAlibaba微服務(wù) 2022.0 + Springboot3.X 集成 Dubbo實(shí)現(xiàn)對外調(diào)用http內(nèi)部調(diào)用RPC

    近期自己新開了一套SpringCloud Alibaba微服務(wù)項(xiàng)目,接口使用了對外HTTP,內(nèi)部RPC的設(shè)計,具體點(diǎn)說就是外部用戶或客戶端通過Nginx訪問到Gateway網(wǎng)關(guān)再分發(fā)到各個服務(wù),內(nèi)部各個服務(wù)之間統(tǒng)一使用Dubbo RPC進(jìn)行通信。下面是Springboot3.x集成Dubbo的分享: 1. 需要的關(guān)鍵依賴 2. 啟動程序入

    2024年02月15日
    瀏覽(25)
  • 13、MongoDB--通過 SpringBoot 整合 Spring Data MongoDB(【連接多個 MongoDB 服務(wù)器】、【高級定制 MongoDB 客戶端】的簡單介紹)

    放棄 Spring Boot 為 MongeDB 提供的自動配置,接下來同樣要干如下事情: 手動配置多組 ReactiveMongoDatabaseFactory 和 ReactiveMongoTemplate,要連幾個 MongoDB 服務(wù)器就配置幾組。 同步 API 則使用 MongoDatabaseFactory 和 MongoTemplate。 針對不同 MongoDB 服務(wù)器,分別開發(fā)相應(yīng)的 DAO 組件類,建議將它

    2024年03月19日
    瀏覽(25)
  • 云原生微服務(wù) 第五章 Spring Cloud Netflix Eureka集成負(fù)載均衡組件Ribbon

    云原生微服務(wù) 第五章 Spring Cloud Netflix Eureka集成負(fù)載均衡組件Ribbon

    第一章 Java線程池技術(shù)應(yīng)用 第二章 CountDownLatch和Semaphone的應(yīng)用 第三章 Spring Cloud 簡介 第四章 Spring Cloud Netflix 之 Eureka 第五章 Spring Cloud Netflix 之 Ribbon Spring Cloud Ribbon 是一套基于 Netflix Ribbon 實(shí)現(xiàn)的客戶端負(fù)載均衡和服務(wù)調(diào)用工具,其主要功能是提供客戶端的負(fù)載均衡算法和服務(wù)

    2024年02月08日
    瀏覽(87)
  • Springboot搭建微服務(wù)案例之Eureka注冊中心

    Springboot搭建微服務(wù)案例之Eureka注冊中心

    放一些pojo類 (1)整合mybatis dao層 創(chuàng)建 dao 接口的映射文件還有 mybatis 的核心配置文件 配置 MyBatis 的類型別名,簡化 MyBatis 映射文件中的配置? (2)Service 使用 RestTemplate 這個 Java 客戶端組件來實(shí)現(xiàn)服務(wù)的遠(yuǎn)程調(diào)用。所以我們需要將 RestTemplate 使用 Java 配置類進(jìn)行注入: 這里

    2024年02月05日
    瀏覽(21)
  • DevOps系列文章 之 SpringBoot整合GitLab-CI實(shí)現(xiàn)持續(xù)集成

    DevOps系列文章 之 SpringBoot整合GitLab-CI實(shí)現(xiàn)持續(xù)集成

    在企業(yè)開發(fā)過程中,我們開發(fā)的功能或者是修復(fù)的BUG都需要部署到服務(wù)器上去,而這部分部署操作又是重復(fù)且繁瑣的工作,GitLab-CI 持續(xù)集成為我們解決了這一痛點(diǎn),將重復(fù)部署的工作自動化,大大的節(jié)省了程序員們的寶貴時間。本文詳細(xì)講述了 GitLab-CI 持續(xù)集成的安裝、部署

    2024年02月13日
    瀏覽(23)
  • 【RabbitMQ】4 Spring/SpringBoot整合RabbitMQ

    spring-amqp 是對AMQP的一些概念的一些抽象, spring-rabbit 是對RabbitMQ操作的封裝實(shí)現(xiàn)。 主要有幾個核心類 RabbitAdmin 、 RabbitTemplate 、 SimpleMessageListenerContainer 等。 RabbitAdmin 類完成對Exchange,Queue,Binding的操作,在容器中管理了 RabbitAdmin 類的時候,可以對Exchange,Queue,Binding進(jìn)行自

    2024年01月22日
    瀏覽(22)
  • SpringBoot整合Spring Security實(shí)現(xiàn)權(quán)限控制

    SpringBoot整合Spring Security實(shí)現(xiàn)權(quán)限控制

    要對Web資源進(jìn)行保護(hù),最好的辦法莫過于Filter 要想對方法調(diào)用進(jìn)行保護(hù),最好的辦法莫過于AOP。 Spring Security進(jìn)行認(rèn)證和鑒權(quán)的時候,就是利用的一系列的Filter來進(jìn)行攔截的。 如圖所示,一個請求想要訪問到API就會從左到右經(jīng)過藍(lán)線框里的過濾器,其中 綠色部分是負(fù)責(zé)認(rèn)證的

    2024年02月15日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包