最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring Cloud入門(mén)系列服務(wù)提供者總結(jié)

 更新時(shí)間:2021年06月16日 14:43:54   作者:全棧阿文  
這篇文章主要介紹了Spring Cloud入門(mén)系列之服務(wù)提供者總結(jié),服務(wù)提供者使用Eureka Client組件創(chuàng)建 ,創(chuàng)建完成以后修改某文件,具體操作方法及實(shí)例代碼跟隨小編一起看看吧

服務(wù)提供者使用Eureka Client組件創(chuàng)建
首先在父項(xiàng)目中創(chuàng)建Eureka Client Server項(xiàng)目(Maven)
創(chuàng)建完成以后,修改pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>com.wenqi.springcloud</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>EurekaClient</artifactId>

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

</project>

編寫(xiě)application.yml文件

server:
  port: 8010
  # 當(dāng)前服務(wù)注冊(cè)在eureka server上的名稱
spring:
  application:
    name: provider
  # 當(dāng)前注冊(cè)中心的訪問(wèn)地址
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  # 是否將當(dāng)前服務(wù)的ip注冊(cè)到Eureka Server
  instance:
    prefer-ip-address: true

創(chuàng)建啟動(dòng)類

@SpringBootApplication
public class ProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class,args);
    }
}

啟動(dòng)啟動(dòng)類,這時(shí)候訪問(wèn)http://localhost:8761/ 可以看到服務(wù)注冊(cè)進(jìn)來(lái)了。
接下來(lái)進(jìn)行增刪改查的簡(jiǎn)單業(yè)務(wù)服務(wù)操作

創(chuàng)建實(shí)體類

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
    private long id;
    private String name;
    private int age;
}

創(chuàng)建repository

public interface StudentRepository {
    public Collection<Student> findAll();
    public Student findById(long id);
    public void saveOrUpdate(Student student);
    public void deleteById(long id);
}

創(chuàng)建repository實(shí)現(xiàn)類

@Repository
public class StudentRepositoryimpl implements StudentRepository {
    private static Map<Long,Student> studentMap;
    static {
        studentMap = new HashMap<Long, Student>();
        studentMap.put(1L,new Student(1L,"張三",22));
        studentMap.put(2L,new Student(2L,"王五",20));
        studentMap.put(3L,new Student(3L,"李四",21));
    }


    public Collection<Student> findAll() {
        return studentMap.values();
    }

    public Student findById(long id) {
        return studentMap.get(id);
    }

    public void saveOrUpdate(Student student) {
        studentMap.put(student.getId(),student);
    }

    public void deleteById(long id) {
        studentMap.remove(id);
    }
}

實(shí)現(xiàn)增刪改查操作 controller

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentRepository studentRepository;
    @GetMapping("/findAll")
    public Collection<Student> findAll(){
        return studentRepository.findAll();
    }
    @GetMapping("/findById/{id}")
    public Student findById(@PathVariable("id") long id){
        return studentRepository.findById(id);
    }
    @PostMapping("/save")
    public void save(@RequestBody Student student){
        studentRepository.saveOrUpdate(student);
    }
    @PutMapping("/update")
    public void update(@RequestBody Student student){
        studentRepository.saveOrUpdate(student);
    }
    @DeleteMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") long id){
        studentRepository.deleteById(id);
    }
}

啟動(dòng)Eureka Client,并啟動(dòng)Eureka Server。
使用postman工具進(jìn)行測(cè)試

在這里插入圖片描述
在這里插入圖片描述

postman的使用自己下去進(jìn)行了練習(xí),不得不說(shuō)測(cè)試還是很有必要的。

以上就是Spring Cloud入門(mén)服務(wù)提供者總結(jié)的詳細(xì)內(nèi)容,更多關(guān)于Spring Cloud服務(wù)提供者的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java數(shù)組(Array)最全匯總(上篇)

    Java數(shù)組(Array)最全匯總(上篇)

    這篇文章主要介紹了Java數(shù)組(Array)最全匯總(上篇),本文章內(nèi)容詳細(xì),通過(guò)案例可以更好的理解數(shù)組的相關(guān)知識(shí),本模塊分為了三部分,本次為上篇,需要的朋友可以參考下
    2023-01-01
  • java中常用的阻塞隊(duì)列與非阻塞隊(duì)列詳解

    java中常用的阻塞隊(duì)列與非阻塞隊(duì)列詳解

    這篇文章主要介紹了java中常用的阻塞隊(duì)列與非阻塞隊(duì)列用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • java批量導(dǎo)入Excel數(shù)據(jù)超詳細(xì)實(shí)例

    java批量導(dǎo)入Excel數(shù)據(jù)超詳細(xì)實(shí)例

    這篇文章主要給大家介紹了關(guān)于java批量導(dǎo)入Excel數(shù)據(jù)的相關(guān)資料,EXCEL導(dǎo)入就是文件導(dǎo)入,操作代碼是一樣的,文中給出了詳細(xì)的代碼示例,需要的朋友可以參考下
    2023-08-08
  • Swing拆分窗格控件JSplitPane使用詳解

    Swing拆分窗格控件JSplitPane使用詳解

    這篇文章主要為大家詳細(xì)介紹了Swing拆分窗格控件JSplitPane的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 使用Postman自動(dòng)生成Cookie并轉(zhuǎn)換為Java代碼的實(shí)現(xiàn)

    使用Postman自動(dòng)生成Cookie并轉(zhuǎn)換為Java代碼的實(shí)現(xiàn)

    在接口測(cè)試中,有時(shí)候需要在請(qǐng)求中攜帶Cookie信息,為了方便測(cè)試,我們可以使用Postman來(lái)自動(dòng)生成Cookie,并將其轉(zhuǎn)換為Java代碼,以便在自動(dòng)化測(cè)試中使用,下面將介紹如何實(shí)現(xiàn)這一功能,需要的朋友可以參考下
    2024-11-11
  • SpringBoot開(kāi)啟異步調(diào)用方法

    SpringBoot開(kāi)啟異步調(diào)用方法

    這篇文章主要為大家詳細(xì)介紹了SpringBoot開(kāi)啟異步調(diào)用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • 淺談JavaIO之try with底層原理

    淺談JavaIO之try with底層原理

    眾所周知,所有被打開(kāi)的系統(tǒng)資源,比如流、文件或者Socket連接等,都需要被開(kāi)發(fā)者手動(dòng)關(guān)閉,否則隨著程序的不斷運(yùn)行,資源泄露將會(huì)累積成重大的生產(chǎn)事故。本文將介紹JavaIO之try with底層原理。
    2021-06-06
  • java -jar指定端口或配置文件啟動(dòng)jar問(wèn)題

    java -jar指定端口或配置文件啟動(dòng)jar問(wèn)題

    這篇文章主要介紹了java -jar指定端口或配置文件啟動(dòng)jar問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Spring實(shí)現(xiàn)定時(shí)任務(wù)的幾種方式總結(jié)

    Spring實(shí)現(xiàn)定時(shí)任務(wù)的幾種方式總結(jié)

    Spring Task 是 Spring 框架提供的一種任務(wù)調(diào)度和異步處理的解決方案,可以按照約定的時(shí)間自動(dòng)執(zhí)行某個(gè)代碼邏輯它可以幫助開(kāi)發(fā)者在 Spring 應(yīng)用中輕松地實(shí)現(xiàn)定時(shí)任務(wù)、異步任務(wù)等功能,提高應(yīng)用的效率和可維護(hù)性,需要的朋友可以參考下本文
    2024-07-07
  • Java基礎(chǔ)教程之String深度分析

    Java基礎(chǔ)教程之String深度分析

    這篇文章主要給大家介紹了關(guān)于Java基礎(chǔ)教程之String的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06

最新評(píng)論

琼海市| 赤峰市| 甘泉县| 大冶市| 宝兴县| 本溪| 定边县| 衢州市| 那坡县| 大城县| 漳浦县| 兴海县| 通榆县| 通城县| 临漳县| 廉江市| 称多县| 拉孜县| 名山县| 九江县| 年辖:市辖区| 湖北省| 长治县| 石景山区| 江城| 资中县| 太和县| 阳朔县| 光泽县| 涞源县| 舞钢市| 林口县| 洛宁县| 榆中县| 南澳县| 浮山县| 鸡东县| 丽水市| 公安县| 淅川县| 阿拉尔市|