亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:18日期: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
相關文章:
主站蜘蛛池模板: 国产精品无 | 国产精品综合色区在线观看 | 色综合色狠狠天天久久婷婷基地 | 国产成人夜间影院在线观看 | 欧美成人一区二区三区不卡视频 | 日本一级毛片冲田杏梨 | 国产精品视频第一页 | 国产精品色午夜视频免费看 | 亚洲国产剧情在线 | 日韩黄色一级 | 精品一区二区在线欧美日韩 | 久久国产精品自线拍免费 | 免费国产一级特黄久久 | 一区二区视屏 | 色婷婷六月丁香七月婷婷 | 国产亚洲欧美日韩在线一区 | 国内精自品线一区91 | 欧美日韩综合网在线观看 | 最新国产精品 | 成人美女免费网站视频 | 350gao免费永久视频 | 欧美高清免费一级在线 | 黄 色 片在观看 | 国产又色又爽黄的网站免费 | 大黄网站在线观看 | jizjizjiz亚洲大全| 99热久久这里只精品国产www | 青草在线观看 | 久久夜色精品 | 亚洲狼人香蕉香蕉在线28 | 精品一区亚洲 | 国产精品三级一区二区 | 国产一级毛片大陆 | 麻豆精品久久精品色综合 | 日韩在线1 | 一级白嫩美女毛片免费 | 久久99青青久久99久久 | 亚洲精品国产成人7777 | 色接久久 | 华人欧美国产在线精品 | 免费在线观看一级片 |