非常感謝http://blog.csdn.net/sun_t89/article/details/51944252
spring Boot實戰之Redis緩衝登入驗證碼
本章簡單介紹Redis的配置及使用方法,本文範例程式碼在前面代碼的基礎上進行修改添加,實現了使用redis進行緩衝驗證碼,以及校正驗證碼的過程。
1、添加依賴庫(添加redis庫,以及第三方的驗證碼庫)
[html] view plain copy <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> </dependency> <dependency> <groupId>cn.apiclub.tool</groupId> <artifactId>simplecaptcha</artifactId> <version>1.2.2</version> </dependency>
2、在application.properties中添加redis的配置資訊
[html] view plain copy spring.redis.database=4 spring.redis.host=hostname spring.redis.password=password spring.redis.port=6379 spring.redis.timeout=2000 spring.redis.pool.max-idle=8 spring.redis.pool.min-idle=0 spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1
3、添加redis資料模版
新增RedisConfig.Java
[java] view plain copy package com.xiaofangtech.sun.config; import org.springframework.context.annotation.Bean; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.StringRedisSerializer; public class RedisConfig { @Bean JedisConnectionFactory jedisConnectionFactory() { return new JedisConnectionFactory(); } @Bean