First of all, to install Redis in the local, specific view (Mac installation): http://blog.csdn.net/kirito_j/article/details/79079411
Project Environment: MAVEN,SPRINGMVC
Pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId> spring-data-redis</artifactid>
<version>1.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactid>jedis</ artifactid>
<version>2.1.0</version>
</dependency>
Xml
<servlet>
<servlet-name>springmvc</servlet-name>
<!--used the Springframe servlet-->.
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
< init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath :/meta-inf/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</ load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</ servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Applicaton.properties
# Redis Settings
redis.host=127.0.0.1
redis.port=6379
redis.pass=
redis.maxidle=300
redis.maxactive=600
redis.maxwait=1000
redis.testonborrow=true
Springmvc-servlet.xml
<!--Redis Cache database related configuration--> <context:property-placeholder ignore-resource-not-found= "true" location=
"Classpath*:application.properties"/> <bean id= "poolconfig" class= "Redis.clients.jedis.JedisPoolConfig" > <property name= "Maxidle" value= "${redis.maxidle}"/> <property name= "maxactive" value= Active} "/> <property name= maxwait" value= "${redis.maxwait}"/> <property name= "Testonborrow" Value= "${redis.testonborrow}"/> </bean> <bean id= "ConnectionFactory" class= Mework.data.redis.connection.jedis.JedisConnectionFactory "P:host-name=" ${redis.host} "p:port=" ${redis.port} "p: Password= "${redis.pass}" p:pool-config-ref= "Poolconfig"/> <bean id= "redistemplate" class= "org.spring" Framework.data.redis.core.StringRedisTemplate "> <property name=" connectionfactory "ref=" ConnectionFactory " > </bean>
Using the method, inject the redistemplate<k,v> with @autowired
Redistemplate specific usage view: https://www.jianshu.com/p/7bf5dc61ca06
Testinterceptor.java
Package com.sms.interceptor;
Import com.sms.model.CourseEntity;
Import Com.sms.repository.CourseRepository;
Import Com.sms.service.redis.RedisService;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.data.redis.core.RedisTemplate;
Import Org.springframework.web.servlet.HandlerInterceptor;
Import Org.springframework.web.servlet.ModelAndView;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import javax.servlet.http.HttpSession;
Import java.util.List;
Import Java.util.Map; public class Testinterceptor implements Handlerinterceptor {@Autowired private redistemplate<string, STRING&G T
Redistemplate; public boolean prehandle (HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, Object o)
Throws Exception {Redistemplate.opsforvalue (). Set ("SessionId", "1111");
System.out.println ("SessionId" + redistemplate.opsforvalue (). Get ("sessionId"); return true; } public void Posthandle (HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, Object o, Mo
Delandview Modelandview) throws Exception {System.out.println ("post"); } public void Aftercompletion (HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, Object
O, Exception e) throws Exception {System.out.println ("after");
}
}