Prepare beforehand
1. Download Redis
https://github.com/MicrosoftArchive/redis/releases/tag/win-3.2.100
2. Download the Redis visualization tool
Https://redisdesktop.com/download
3. Start Redis
CD%redis%
Redis-server.exe
Configuration
4, Pom.xml additional
Spring-data-redis
Jedis
5. New Redis/redis.properties
redis.hostname=localhostredis.port=6379#redis.password=
6. New Springframework/spring-redis.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans. XSD Http://www.springframework.org/schema/context http://www.springframework.org/schema/cont Ext/spring-context.xsd "> <Context:property-placeholder Location= "Classpath:redis/redis.properties"ignore-unresolvable= "true" /> <BeanID= "Redisconnectionfactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> < Propertyname= "HostName"value= "${redis.hostname}" /> < Propertyname= "Port"value= "${redis.port}" /> </Bean> <BeanID= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate"> < Propertyname= "ConnectionFactory"ref= "Redisconnectionfactory" /> </Bean> <BeanID= "CacheManager"class= "Org.springframework.data.redis.cache.RedisCacheManager"> <Constructor-argref= "Redistemplate" /> < Propertyname= "Defaultexpiration"value= " the" /> </Bean></Beans>
8, ensure that spring-redis.xml can be introduced into the Application-context.xml
<resource= "Classpath:springframework/spring-*.xml"/>
7. At this point, the cache can be implemented by appending @cacheable @CachePut @CacheEvict to the method of the Serviceimpl class.
Configure Spring Data Redis