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