# spring-boot-starter-guava
**Repository Path**: itunion/spring-boot-starter-guava
## Basic Information
- **Project Name**: spring-boot-starter-guava
- **Description**: 微服务架构实战篇(五):Spring boot2.x + Guava 并使用RateLimiter秒杀限流
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 1
- **Created**: 2019-03-15
- **Last Updated**: 2022-07-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 简介
该项目主要利用Spring boot2.x 集成 Guava 实现数据缓存,并使用RateLimiter做秒杀限流示例Demo。
* Guava是一种基于开源的Java库,其中包含谷歌正在由他们很多项目使用的很多核心库。这个库是为了方便编码,并减少编码错误。这个库提供用于集合,缓存,支持原语,并发性,常见注解,字符串处理,I/O和验证的实用方法。
* Guava - RateLimiter使用的是一种叫令牌桶的流控算法,RateLimiter会按照一定的频率往桶里扔令牌,线程拿到令牌才能执行。
* [Google guava工具类快速入门指南](https://www.jianshu.com/p/7b2cb82dcd21)
* 源码地址
* GitHub:[https://github.com/yundianzixun/spring-boot-starter-guava](https://github.com/yundianzixun/spring-boot-starter-guava)
* 联盟公众号:IT实战联盟
* 我们社区:[https://100boot.cn](https://100boot.cn)
**小工具一枚,欢迎使用和Star支持,如使用过程中碰到问题,可以提出Issue,我会尽力完善该Starter**
# 版本基础
* Spring Boot:2.0.4
* Guava:19.0
### 操作步骤
#### 第一步:添加maven依赖
```
org.springframework.boot
spring-boot-starter-cache
com.google.guava
guava
19.0
```
#### 第二步:增加GuavaCacheConfig 配置
GuavaCacheConfig.java
```
package com.itunion.guava.config;
import com.google.common.cache.CacheBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import java.util.concurrent.TimeUnit;
/**
* Created by lin on 19/3/14.
*/
@EnableConfigurationProperties(GuavaProperties.class)
@EnableCaching
@Configuration
public class GuavaCacheConfig {
@Autowired
private GuavaProperties guavaProperties;
@Bean
public CacheBuilder