SSM框架快速集成redis
来源:互联网 发布:淘宝店招制作要点 编辑:程序博客网 时间:2024/06/05 10:26
SSM框架快速集成redis
1.添加maven依赖
<!-- 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>
注:org.springframework.data、org.apache.commons、redis.clients三者的版本必须统一,不然编译时会出现各种版本冲突。(即这种错误信息:java.lang.NoSuchMethodError)这里三者的版本分别为(亲测可用):
<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.编辑redis连接信息
redis.host=192.168.137.111redis.port=6379redis.password=redis.maxIdle=300redis.maxWaitMillis=1000redis.maxTotal=600redis.testOnBorrow=trueredis.testOnReturn=trueredis.projectNam=ssm_redis
3.配置redis-context.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" 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"> <!--扫描redis配置文件--> <context:property-placeholder ignore-unresolvable="true" location="classpath:properties/redis.properties"/> <!--设置连接池--> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}"/> <property name="maxTotal" value="${redis.maxTotal}" /> <property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> <property name="testOnReturn" value="${redis.testOnReturn}" /> </bean> <!--设置链接属性--> <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-config-ref="poolConfig" p:timeout="100000"/> <!-- Jedis模板配置 --> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> </bean></beans>
4.spring引入redis配置文件
<?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"> <!-- 引入redis属性配置文件 --> <import resource="classpath:cache/redis-context.xml"/></beans>
5.单元测试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", "陈梓平"); log.info("value:"+redisTemplate.opsForValue().get("chen")); }}
到此ssm整合redis已经完美嵌入。
阅读全文
0 0
- SSM框架快速集成redis
- 快速集成搭建SSM框架
- SSM框架集成Redis数据库【Redis·4】
- redis+ssm集成
- SSM框架(二级缓存)集成Redis单机模式及哨兵模式
- SSM框架集成
- Maven集成SSM框架
- ssm框架集成详解
- ssm集成框架freemarker
- SSM框架集成
- SSM集成Redis做缓存
- SSM框架快速搭建
- SSM框架快速搭建
- SSM框架的集成整合
- ssm框架集成Quartz定时器
- SSM集成安全框架shiro
- SSM框架和Redis整合
- 快速集成MyBeatis框架
- python: del函数
- Magento获取商品的评价列表(get product review)
- SI24R2B 单发Tx发射芯片功耗低
- PNG图片压缩方法
- 树莓派remot3.it外网访问最新--安装weavedconnectd
- SSM框架快速集成redis
- java GC机制
- PostgreSQL初安装小记
- linux服务器部署环境(阿里云 centos7.4 64位+ jdk+tomcat+mysql安装)
- Redis持久化(persistence)
- C
- 分水岭的迭代计算具体过程解释
- Struts类型转换(以日期为例)
- sql server数据库之存储过程