springCould注解和配置以及pom依赖
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} |
springCould注解和配置以及pom依赖的更多相关文章
- SpringCloud注解和配置以及pom依赖说明
在本文中说明了pom依赖可以支持什么功能,以及支持什么注解,引入该依赖可以在application.properties中添加什么配置. 1.SpringCloud 的pom依赖 序号 pom依赖 说 ...
- Bean 注解(Annotation)配置(3)- 依赖注入配置
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- SpringBoot第二集:注解与配置(2020最新最易懂)
2020最新SpringBoot第二集:基础注解/基础配置(2020最新最易懂) 一.Eclipse安装SpringBoot插件 Eclipse实现SpringBoot开发,为便于项目的快速构建,需要 ...
- (转)maven配置之pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- Spring注解和配置方式
Spring提供了一个org.springframework.beans.factory.FactoryBean工厂类接口,用户可以通过实现该接口定制实例化Bean的逻辑. 从Spring3.0开始, ...
- Spring 基于注解零配置开发
本文是转载文章,感觉比较好,如有侵权,请联系本人,我将及时删除. 原文网址:< Spring 基于注解零配置开发 > 一:搜索Bean 再也不用在XML文件里写什么配置信息了. Sprin ...
- Spring3+SpingMVC+Hibernate4全注解环境配置
Spring3+SpingMVC+Hibernate4全注解环境配置 我没有使用maven,直接使用Eclipse创建动态Web项目,jar包复制在了lib下.这样做导致我马上概述的项目既依赖Ecli ...
- 使用纯注解与配置类开发springMVC项目,去掉xml配置
最近拜读了杨开振老师的书,深入浅出springBoot2.x,挖掘了很多以前被忽略的知识, 开发一年多,工作中一直用传统springmvc的开发,基本都还是用的传统的xml配置开发, 看到书里有提到, ...
- struts 多文件上传 annotation注解(零配置)+ ajaxfileupload + 异步 版本
[本文简介] struts 多文件上传.基于”零配置“+"ajaxfileupload" 的一个简单例子. [导入依赖jar包] jquery-1.7.2.js : http:// ...
随机推荐
- 连接mysql出现“Unable to load authentication plugin 'caching_sha2_password”错误
这是mysql 8.0版本才出现的问题,原因是mysql 8.0 默认使用 caching_sha2_password 身份验证机制 -- 从原来的 mysql_native_password 更改为 ...
- NSInvocation的基本使用
//封装invacation可以调用多个参数的方法 -(void)invacation { //1.创建一个MethodSignature,签名中保存了方法的名称,参数和返回值 //这个方法属于谁,那 ...
- Docker的资源控制管理
Docker的资源控制管理 1.CPU控制 2.对内存使用进行限制 3.对磁盘I/O配额控制的限制 1.CPU控制: cgroups,是一个非常强大的linux内核工具,他不仅可以限制被namespa ...
- C++学习笔记_complex类的实现
头文件中的防卫式声明 点击查看代码 #ifndef __COMPLEX__ #define __COMPLEX__ class complex { } #endif 类的定义 点击查看代码 class ...
- Python实现不带头结点的单链表
1 # 创建一个节点类 2 class Node: 3 def __init__(self, item): 4 self.item = item 5 self.next = None 6 7 8 # ...
- Keycloak 团队宣布他们正在弃用大多数 Keycloak 适配器,包括Spring Security和Spring Boot
2月14日,Keycloak 团队宣布他们正在弃用大多数 Keycloak 适配器. 其中包括Spring Security和Spring Boot的适配器,这意味着今后Keycloak团队将不再提供 ...
- Vue.use初探
Vue.use 问题 相信很多人在用Vue使用别人的组件时,会用到 Vue.use(). 例如:Vue.use(VueRouter).Vue.use(MintUI). 但是用 axios时,就不需要用 ...
- Unable to register node “xxx“ with API server: Unauthorized
k8s二进制部署环境出现kubelet认证不了节点 出现这个情况的时候,第一个反应是先看apiserver证书是不是过期了 # 查看apiserver的service文件存储路径 systemctl ...
- C# 实例解释面向对象编程中的里氏替换原则
在面向对象编程中,SOLID 是五个设计原则的首字母缩写,旨在使软件设计更易于理解.灵活和可维护.这些原则是由美国软件工程师和讲师罗伯特·C·马丁(Robert Cecil Martin)提出的许多原 ...
- 施耐德NOE77101后门漏洞分析
固件下载地址: GitHub - ameng929/NOE77101_Firmware 文件目录结构,这里只列出了一些主要的文件信息: ├── bin ├── ftp ├── fw ├── rdt ├ ...