Redis and Spring Consolidation examples

Source: Internet
Author: User

1) The first is the Redis configuration.

Using MAVEN engineering to introduce the associated jar packages for Redis and spring integration

<!--Redis Services start-->        <dependency>          <groupId>org.springframework.data</groupId>          <artifactId>spring-data-redis</artifactId>          <version>1.6.2.RELEASE</version>        </dependency>        <dependency>          <groupId>redis.clients</groupId>          < artifactid>jedis</artifactid>          <version>2.6.2</version>        </dependency>        <!--Redis service end-->

2) Add the appropriate profile to Redis: Spring-redis.xml content

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:jee= "Http://www.springframework.org/schema/jee" xmlns:tx= "Http://www.springframework.org/schema/tx"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "http://Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><bean id= "Poolconfig"class= "Redis.clients.jedis.JedisPoolConfig" > <property name= "maxidle" value= "${redis.maxidle}"/> &LT;PR Operty name= "Maxtotal" value= "${redis.maxactive}"/> <property name= "Maxwaitmillis" value= "${redis.maxWait}" /> <property name= "Testonborrow" value= "${redis.testonborrow}"/> </bean> <bean id= "JedisCo Nnectionfactory "class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" > <property name= "poolconfig" ref= "Poolconfig"/> <property name= "port" value= "${redis.port}"/> <property name= "HostName" Val Ue= "${redis.host}"/> <property name= "password" value= "${redis.pass}"/> </bean> <be An id= "Stringserializer"class= "Org.springframework.data.redis.serializer.StringRedisSerializer"/> <bean id= " Jdkserializationredisserializer "class= "Org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> <bean id= " Stringredistemplate "class= "Org.springframework.data.redis.core.StringRedisTemplate" > <property name= "connectionfactory" ref= " Jedisconnectionfactory "/> <property name=" Keyserializer "ref=" Stringserializer "/> <property na Me= "ValueSerializer" ref= "Jdkserializationredisserializer"/> </bean> <bean id= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate" > <property name= "connectionfactory" ref= " Jedisconnectionfactory "/> <property name=" Keyserializer "ref=" Stringserializer "/> <property na Me= "ValueSerializer" ref= "Jdkserializationredisserializer"/> </bean></beans>

3) Configure the required parameters for Redis connection pooling in application

#redis连接配置 ===================start=========================# Redis settingsredis.host=192.168.10.102 redis.port=6379redis.pass=redis.maxidle=1redis.maxactive =9  Redis.maxwait=1000redis.testonborrow=true#redis连接配置===================end===== ====================

4) Introduce the appropriate configuration information in Web. xml

<!--contextloaderlistener contextconfiglocation parameters to use when initializing the spring context--    <context-param>        <param-name>contextConfigLocation</param-name>        <!-- Configure the location of both the Spring.xml and spring-mybatis.xml configuration files, pin-to-        <param-value>            classpath:spring.xml,            classpath:spring-mybatis.xml,            classpath:spring-activitymq.xml,            classpath: Dubbo.xml,            classpath:spring-redis.xml        </param-value>    </context-param>

5) Start the Tomcat service and start normal.

Redis and Spring Consolidation examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.