前言
本篇笔记为尚硅谷发布的2024springCloud的个人学习笔记,练习的项目为自己的练习项目与尚硅谷视频中的项目还有版本等皆有些不同。(最后也是会记录一些因为 版本问题或者因为微服务所踩的一些小坑)
1.springCould各个组件大纲
2.服务注册Consul
服务注册中心是集中管理微服务,实现服务的注册,发现,检查等功能。是微服务中很重要的组件。参见的服务注册中心有Eureka和nocas,consul等等。推荐consul和nocas。
为什么不使用Eureka了
1.Eureka官方已经停止维护了。(被Apache接手更新)
2.Eureka是通过实现微服务项目,不能够很好的与其他微服务进行解耦(就是要写代码来实现)
3.阿里巴巴的nocas很火,还能作为配置中心。
4.至于两者CP和AP原则各有优劣
怎么使用Consul
1.安装consul
Install | Consul | HashiCorp Developer
2.项目结构
3.pom
<!--SpringCloud consul discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
4.配置文件
5.主启动类添加注解
@SpringBootApplication
@EnableDiscoveryClient//开启服务发现
public class userProviderApplication {
public static void main(String[] args) {
SpringApplication.run(userProviderApplication.class, args);
}
}
6.启动项目即可注册进入到服务注册中心