SSM Framework Fast Integration REDIS_SSM

Source: Internet
Author: User
SSM Framework Fast Integration Redis 1. Add maven Dependencies
<!--config Redis data and client jar-->
<dependency>
    <groupid>org.springframework.data </groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>${ spring.redis.version}</version>
</dependency>
<!--https://mvnrepository.com/artifact/ Org.apache.commons/commons-pool2-->
<dependency>
    <groupid>org.apache.commons</ groupid>
    <artifactId>commons-pool2</artifactId>
    <version>${commons.version}</ version>
</dependency>
<!--Https://mvnrepository.com/artifact/redis.clients/jedis-->
<dependency>
    <groupId>redis.clients</groupId>
    <artifactid>jedis</ artifactid>
    <version>${jedis.version}</version>
</dependency>

Note: The versions of Org.springframework.data, Org.apache.commons, redis.clients must be unified, or there will be conflicting versions of the compilation. (That is, this error message: Java.lang.NoSuchMethodError) Here are the versions of the three (pro-Test available):

<spring.redis.version>1.6.0.RELEASE</spring.redis.version>
<jedis.version>2.7.2</ Jedis.version>
<commons.version>2.4.2</commons.version>
2. Edit Redis Connection Information
redis.host=192.168.137.111
redis.port=6379
redis.password=

redis.maxidle=300
redis.maxwaitmillis=1000
redis.maxtotal=600
redis.testonborrow=true
redis.testonreturn=true

Redis.projectnam=ssm_redis
3. Configure Redis-context.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" Xmlns:contex t= "Http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.org/s Chema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframewor K.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <!--scanning redis matching Set file--> <context:property-placeholder ignore-unresolvable= "true" location= classpath:properties/ 
        Redis.properties "/> <!--set Connection pool--> <bean id=" Poolconfig "class=" Redis.clients.jedis.JedisPoolConfig "> <property name= "Maxidle" value= "${redis.maxidle}"/> <property name= "Maxtotal" value= Total} "/> <property name="Maxwaitmillis "value=" ${redis.maxwaitmillis} "/> <property name=" Testonborrow "value=" ${redis.testOnBorrow} " /> <property name= "Testonreturn" value= "${redis.testonreturn}"/> </bean> <!--set link Properties--&
    Gt <bean id= "ConnectionFactory" class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p : Hostname= "${redis.host}" p:port= "${redis.port}" p:password= "${redis.password}" P:pool-confi g-ref= "Poolconfig" p:timeout= "100000"/> <!--Jedis template configuration--> <bean id= "Redistemplate" Org.springframework.data.redis.core.StringRedisTemplate "> <property name=" connectionfactory "ref=" connecti
 Onfactory "/> </bean> </beans>
4.spring introduction of Redis configuration file
<?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:context= "http://www.springframework.org/ Schema/context "
       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/context/spring-context.xsd ">

    <!--introduce Redis property profile-->
    < Import resource= "Classpath:cache/redis-context.xml"/>

</beans>
5. Unit Test Redis
/**
 * @Author: Catalpaflat
 * @Descrition:
 * @Date: Create in 10:08 2017/11/8
 * @Modified by:
* @RunWith (Springrunner.class)
@ContextConfiguration ({"Classpath:spring/*.xml"}) public
class Testredis {

    @Autowired
    private redistemplate redistemplate;

    Private static final Logger log  = Logger.getlogger (TestRedis.class.getName ());

    @Test public
    void Test () {
        redistemplate.opsforvalue (). Set ("Chen", "Chen Ziping");
        Log.info ("Value:" +redistemplate.opsforvalue (). Get ("Chen"));
    }

To this SSM integration Redis has been perfectly embedded.

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.