【服务容器限流 QPS策略之(一)hystrix 】
本次篇想说的是一定要注意各种 组建版本冲突的问题
spring boot 是 2.2.0.RELEASE 最新版本
从网上看到的坑---- -注意勿抄
原本好好的springboot demo 启动失败 报错信息如下:
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.springbootgit.SpringbootgitApplication.main(SpringbootgitApplication.java:14)
Process finished with exit code 1
【解决方案】
打开maven 官网 或者复制下方 依赖
<!--hystrix断路器maven依赖 保护服务器 防止服务器雪崩-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
第二坑:mysql 连接报错
因为不仅仅只需要mysql 缺少jpa依赖。以下这段包治百病
<!-- MyBatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <!--Mysql数据库驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.15</version> </dependency> <!--集成druid连接池--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
哦了,项目通过hystrix 控制API 的QPS 来保护服务 金枪不倒。
下次分享更加屌炸天的 Google 秒杀业务场景 ,限流神器 guava (瓜娃子)~