av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Spring Cloud入門系列服務提供者總結

瀏覽:59日期:2023-07-09 14:53:24

服務提供者使用Eureka Client組件創建首先在父項目中創建Eureka Client Server項目(Maven)創建完成以后,修改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>

編寫application.yml文件

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

創建啟動類

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

啟動啟動類,這時候訪問http://localhost:8761/ 可以看到服務注冊進來了。接下來進行增刪改查的簡單業務服務操作

創建實體類

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

創建repository

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

創建repository實現類

@Repositorypublic 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); }}

實現增刪改查操作 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); }}

啟動Eureka Client,并啟動Eureka Server。使用postman工具進行測試

Spring Cloud入門系列服務提供者總結Spring Cloud入門系列服務提供者總結

postman的使用自己下去進行了練習,不得不說測試還是很有必要的。

以上就是Spring Cloud入門服務提供者總結的詳細內容,更多關于Spring Cloud服務提供者的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
主站蜘蛛池模板: 欧美一区二区大片 | 九九九久久国产免费 | 国产日韩精品视频 | av二区三区 | 亚洲视频www| 男女羞羞视频网站 | 男女羞羞视频在线免费观看 | 最新中文字幕第一页视频 | 91在线视频网址 | 日韩播放| 久久久久亚洲精品中文字幕 | 一区二区在线 | 99国内精品久久久久久久 | 亚av在线 | 成人午夜免费网站 | 国产区一区 | 欧美激情亚洲 | 亚洲精品视频在线观看免费 | 成人性生交大片免费看r链接 | 亚洲精品一区二区三区中文字幕 | 欧美久久精品一级黑人c片 91免费在线视频 | 91在线观看免费 | 91高清在线观看 | 国产日韩免费观看 | 精品一区二区三区四区五区 | 一本色道精品久久一区二区三区 | 亚洲三级av| 日韩中文字幕一区 | 国产成视频在线观看 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 国产婷婷精品av在线 | 日韩中文字幕在线观看 | 国产亚洲精品美女久久久久久久久久 | 一区二区三区在线播放 | 精品久久久久久 | 91人人视频在线观看 | 91久久久久久| 欧美成人a∨高清免费观看 欧美日韩中 | 国产激情视频在线观看 | wwwww在线观看 | www.99热|