SpringCloud注解和配置以及pom依赖说明
在本文中说明了pom依赖可以支持什么功能,以及支持什么注解,引入该依赖可以在application.properties中添加什么配置。
1、SpringCloud 的pom依赖
序号 | pom依赖 | 说明 | 支持注解 | 支持配置application.properties |
1 |
<parent> |
spring-boot-starter-parent是Spring Boot的核心启动器, |
@SpringBootApplication |
server.port=1111 |
2 |
<dependencyManagement> |
使用dependencyManagement进行版本管理 |
||
3 |
<dependency> |
支持HTTP调用方式,包含了Spring Boot预定义的一些Web开发的常用依赖包 |
||
4 |
<dependency> |
@SpringCloudApplication | spring.application.name=eureka-service | |
5 |
<dependency> |
eureka注册中心依赖 | @EnableEurekaServer |
eureka.instance.hostname=localhost |
6 |
<dependency> |
引入eureka 客户端依赖 |
@EnableDiscoveryClient |
|
7 |
<dependency> |
引入ribbon 依赖 ,用来实现客户端的负载均衡,用在client客户端项目 |
ribbon.ConnectTimeout=500 |
|
8 |
<dependency> |
引入hystrix 依赖 ,用来实现服务容错保护。当发现请求的服务端崩溃,就采用容错机制 | @EnableCircuitBreaker | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 |
9 |
<dependency> |
引入feign 依赖,包含ribbon负载均衡,也包含Hystrix服务容错。 Spring Cloud Feign在构建被@FeignClient注解修饰的服务客户端是,会为每一个客户端都创建一个feign.Logger实例,我们可以利用该日志对象进行Log分析。 |
@EnableFeignClients |
feign.compression.request.enabled=true; |
10 |
<dependency> |
监控模块,实时和定时监控服务的各项状态和可用性 | ||
11 |
<dependency> |
引入zuul依赖 , 它依赖了spring-boot-starter-actuator/spring-boot-starter-hystrix/spring-boot-starter-ribbon | @EnableZuulProxy |
zuul.routes.api-a.path=/api-a/** |
12 |
<dependency> |
为分布式系统中的基础设施和微服务提供集中化的外部配置支持,分为服务端和客户端两个部分。 |
@EnableConfigServer |
#配置Git仓库的地址 |
13 |
<dependency> |
分布式服务中管理配置文件的客户端,服务端是spring-cloud-config-server | @RefreshScope |
bootstrap.properties: |
14 |
<dependency> |
在所有需要链路跟踪的项目中都加上这个依赖。 | @EnableZipkinServer |
除了sleuth本身是链路中心的除外,其余参与链路追踪的分布式系统都需要添加如下配置: |
15 |
<dependency> |
修改源文件后系统自动重启 | ||
16 |
<plugin> |
告诉Maven包含Spring特定的Maven插件,用于构建和部署SpringBoot应用程序。 |
||
17 |
<plugin> |
部署以及持续集成。 |
||
18 |
<dependency> |
使用Java Persistence API ( JPA ) |
@Entity // 这是一个JPA类 |
|
19 |
<dependency> |
Postgres JDBC驱动程序 | ||
20 |
<dependency> |
加密解密相关包 |
spring.datasource.password: "{cipher}d495ce8603af9676450736e119" |
2、SpringCloud相关注解
序号 | 注解 | 说明 |
1 | @SpringBootApplication | SpringBoot启动类注解,启动类需有main方法 |
2 | @EnableEurekaServer | 用来指定该项目为Eureka的服务注册中心 |
3 | @EnableCircuitBreaker | 开启断路器,实现服务容错保护 |
4 | @EnableDiscoveryClient | 让服务使用eureka服务器 实现服务注册和发现 |
5 | @SpringCloudApplication |
相当于3个注解:@EnableDiscoveryClient |
6 | @Configuration | 相当于定义spring配置文件的xmlns域,以及支持@Bean在本类中的注册。 |
7 | @EnableFeignClients | Spring Cloud Feign 通过@EnableFeignClients来开启spring cloud feign的支持功能 不仅包含Spring Cloud ribbon负责均衡功能,也包含Spring Cloud Hystrix服务容错功能,还提供了一种声明式的Web服务客户端定义方式。 |
8 | @RequestBody | 使接收到的字段值自动映射到注解声明的复合对象中 |
9 | @RestController | @RestController = @Controller + @ResponseBody |
10 | @ComponentScan(basePackages={"com.xx","com.yy"}) | 指定扫描包 |
11 | @EnableZuulProxy |
开启网关路由服务功能。 |
12 | @Bean | 向spring容器注册自定义类 |
13 | @EnableConfigServer | 开启Spring Cloud Config 的服务端功能。为分布式系统中的基础设施和微服务提供集中化的外部配置支持,分为服务端和客户端两个部分。 |
14 | @EnableZipkinServer | 用于开启Zipkin Server功能:分布式框架中的如果发生异常可链路追踪. |
15 |
@RequestMapping(value="/url",method=RequestMethod.POST) |
如何动态配置url路径,以及从路径中取值 |
16 | @RefreshScope | 对需要刷新的属性使用@Value注解,同时将类使用@RefreshScope注解进行标记 |
3、SpringCloud的application.properties相关设置
序号 | application.properties配置 | 说明 |
1 | server.port=1111 | 设置web项目服务端口号 |
2 | spring.application.name=eureka-service | 设置服务名称 |
3 | eureka.instance.hostname=localhost | 设置服务主机IP |
4 | eureka.client.register-with-eureka=false | false: 注册中心不需要注册自己。true(默认): 需要注册自己 |
5 | eureka.client.fetch-registry=false | false: 注册中心不需要去发现服务。true(默认): 需要发现服务 |
6 | eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka | 设置服务注册中心的URL,这里的${}是占位符。最终显示例如:http://localhost:1111/eureka |
7 | ribbon.ConnectTimeout=500 | 全局配置负载均衡超时设置 ribbon.<key>=<value> |
8 | ribbon.ReadTimeout=5000 | 全局配置负载均衡读超时设置 |
9 | hello-service.ribbon.ConnectTimeout=500 | 为某服务指定的负载均衡超时设置 @FeignClient(value="hello-service") |
10 | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 | hystrix.command.default.xxx进行全局配置 |
11 | hystrix.command.hello.execution.isolation.thread.timeoutInMilliseconds=5000 | hystrix.command.<commandKey>.xxx进行指定配置,这里的<commandKey>可以为方法名 |
12 |
feign.compression.request.enabled=true; |
请求压缩配置,支持对请求和响应进行GZIP压缩,以减少通信过程中的性能损耗。 |
13 |
zuul.routes.api-a.path=/api-a/** |
请求示例:http://localhost:5555/api-a/feign-consumer |
14 |
#配置Git仓库的地址 |
SpringCloud自己创建的管理配置中心的服务端配置 |
15 |
spring.profiles.active=default |
指定服务运行什么配置,比如application-dev.properties,就设置值为dev |
16 |
spring.cloud.config.server.encrypt.enabled=false |
显式关闭输出属性的解密。 |
17 |
spring.datasource.password: "{cipher}d495ce8603af9676450736e119" |
SpringCloud配置服务器要求所有已加密的属性前面加上{cipher} |
转载于:https://www.cnblogs.com/zhuwenjoyce/p/9663324.html
SpringCloud注解和配置以及pom依赖说明相关推荐
- springcloud(九):配置中心和消息总线(配置中心终结版)
我们在springcloud(七):配置中心svn示例和refresh中讲到,如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码发送请求来刷新客户端 ...
- springcloud之服务配置中心
SpringCloud Config简介 Spring Cloud Config 是 Spring Cloud 团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持 ...
- docker 安装nacos_19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心
SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...
- SpringCloud之分布式配置中心(六)
简介 SpringCloudConfig就是我们通常意义上的配置中心,把应用原本放在本地文件的配置抽取出来放在中心服务器,从而能够提供更好的管理.发布能力.SpringCloudConfig分服务端和 ...
- springcloud(七):配置中心svn示例和refresh
上一篇springcloud(六):配置中心git示例留了一个小问题,当重新修改配置文件提交后,客户端获取的仍然是修改前的信息,这个问题我们先放下,待会再讲.国内很多公司都使用的svn来做代码的版本控 ...
- SpringCloud Config 分布式配置
SpringCloud Config 分布式配置 Dalston.RELEASE Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持.使用Config Server, ...
- SpringBoot数据访问Mybatis注解版,配置版,注解与配置一体版
SpringBoot数据访问Mybatis注解版,配置版,注解与配置一体版 注解版: 1.改druid 连接池,不改可以跳过这步 添加依赖 <dependency><groupId& ...
- ssm注解配置连接mysql_基于注解和配置类的SSM(Spring+SpringMVC+Mybatis)项目详细配置...
在上一篇文章中介绍了使用注解和xml配置文件对项目进行配置,在这篇文章中将xml配置文件中的配置信息都改成使用注解或者配置类的形式. 第一步.配置pom.xml 在一个ssm项目中,可能需要用到的依赖 ...
- SpringCloud版本Hoxton SR5 --- 第七讲:SpringCloud Config 分布式配置中心+整合bus、rabbitmq、actuator
传送门:SpringCloud版本Hoxton SR5 --- 第一讲:认识 先看SpringCloud Config 可以完成的功能,或者说他在项目中的定位和作用. SpringCloud conf ...
最新文章
- hdu1255 覆盖的面积(线段树面积交)
- vue 使用sass 和less
- bzoj 3209: 花神的数论题
- 玩转 Linux 之:磁盘分区、挂载知多少?
- 下载 嵌入式qt实战教程pdf_Qt之JSON教程-实战篇
- ehcache常用API整理
- 牛客小白月赛8: I. 路灯孤影(区间DP)
- 《图解算法》第11章之 接下来如何做
- 【C语言】九九乘法口诀表
- 在32bit操作系统下用好4GB物理内存
- Revel模板引擎Template基本语法
- Android CPU 双核,为何安卓八核CPU不如苹果双核?
- 2019年一级消防工程师备考八步法
- SATA硬盘与IDE硬盘的优劣势对比
- WhatsApp 公开群营销方案
- 网络犯罪市场Deer.io俄罗斯管理员在美国被判入狱
- 骨传导耳机的几大弊端?骨传导耳机优缺点分析
- 国内外代码生成器大全
- 2019最强一键刷机root教程,安卓用户必备!附带工具分享~
- 【C语言】结构体排序
热门文章
- 【点阵液晶编程连载一】写在前面
- 写给测试人的保姆级涨薪跳槽面试指南
- 自定义ScrollView控件 -- 拉申时跟随缩放效果
- python日志模块----logging
- html 通用ui css图标,ui-icon.html
- R语言chorolayer_R成精系列-R 错误汇总
- 如何得到当前浏览器是什么
- 【Flink】FLink SQL 如何使用嵌套格式的Schema
- 【Flink】Direct buffer memory taskmanager.memory.task.off-heap.size
- 【Elasticsearch】 Elasticsearch并发冲突问题