Spring Boot實戰之Redis緩衝登入驗證碼

來源:互聯網
上載者:User

非常感謝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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.