1、pom

<modelVersion>4.0.0</modelVersion>
<groupId>com.x.redis</groupId>
<artifactId>springredis</artifactId>
<version>0.0.1-SNAPSHOT</version> <dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.2.RELEASE</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.1.0</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

  2、spring配置文件(applicationContext.xml):

<?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/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"> <context:property-placeholder location="classpath:redis.properties" /> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxActive" value="${redis.maxActive}" />
<property name="maxWait" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean> <bean id="connectionFactory" class="org.springframework.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.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean> <bean id="userDao" class="com.x.dao.impl.UserDao" />
</beans> //另一种
<bean id="jedisPool0" class="redis.clients.jedis.JedisPool">
<constructor-arg name="poolConfig" ref="jedisPoolConfig"/>
<constructor-arg name="host" value="${redis.ip}" type="java.lang.String"/>
<constructor-arg name="port" value="${redis.port}" type="int"/>
<constructor-arg name="timeout" value="2000" type="int"/>
<constructor-arg name="password" value="${redis.password}"/>
<constructor-arg name="database" value="0" type="int"/>
</bean>

  3、redis.properties

# Redis settings
redis.host=localhost
redis.port=6379
redis.pass=java2000_wl redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true

  

最新文章

  1. Python为什么不隐式实现self
  2. UrlRewrite伪静态
  3. 【枚举】bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
  4. 改变dijit的长度的心得
  5. 多线程的练习----妖,等待唤醒,代码重构,lock到condition
  6. C++程序员笔试复习概要(一)
  7. 爬坑之路---Google map
  8. java将图片传为设定编码值显示(可做刺绣)
  9. nginx保持会话的方式
  10. 查找网内活跃IP和自动传输文本
  11. Restful风格wcf调用
  12. datagrid在MVC中的运用09-实现排序
  13. CSS编写指导规范和建议
  14. HDU 1198
  15. 「SDOI2008」洞穴勘测
  16. MySQL 中的数据类型介绍
  17. 如果想要跨平台,在file类下有separtor(),返回锁出平台的文件分隔符
  18. linux怎么上真正的国际互联网
  19. Struts2(九.利用layer组件实现图片显示功能)
  20. numpy.linspace介绍

热门文章

  1. install phpexcel using composer in thinkPHP
  2. 页面Button/Link 传参数
  3. 一个section刷新 一个cell刷新
  4. WPF中通过代码设置控件的坐标
  5. [linux系统]查看内核版本和系统版本方法
  6. [mysql]throw exception
  7. webstorm2016.2 for mac 安装
  8. 【前端】【转】JS跨域问题总结
  9. Linux命令:screen
  10. moq 的常用使用方法