Spring RedisTemplate操作-xml配置(1)
网上没能找到全的spring redistemplate操作例子,故特意化了点时间做了接口调用练习,基本包含了所有redistemplate方法。
该操作例子是个系列,该片为spring xml配置,方便后面做各个数据类型的操作。
Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理。它支持字符串、哈希表、列表、集合、有序集合,位图,hyperloglogs等数据类型。内置复制、Lua脚本、LRU收回、事务以及不同级别磁盘持久化功能,同时通过Redis Sentinel提供高可用,通过Redis Cluster提供自动分区。
<context:annotation-config />
<!-- 把非@Controller注解的类转换为bean -->
<context:component-scan base-package="tk.tankpao" />
<cache:annotation-driven />
<context:property-placeholder
location="classpath:conf/properties/redis.properties" />
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- jedis 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- redis服务器中心 -->
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<property name="password" value="${redis.password}" />
<property name="timeout" value="${redis.timeout}"></property>
</bean>
<bean id="redisTemplate" name="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
<!-- <property name="enableTransactionSupport" value="true"/> -->
</bean>
<bean id="jdkredisTemplate" name="jdkredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="jdkSerializationRedisSerializer" />
<property name="valueSerializer" ref="jdkSerializationRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
</bean>
<bean id="jacksonredisTemplate" name="jacksonredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="jackson2JsonRedisSerializer" />
<property name="valueSerializer" ref="jackson2JsonRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
</bean>
<bean id="stringRedisSerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="jackson2JsonRedisSerializer"
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
<bean id="jdkSerializationRedisSerializer"
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
<!-- 配置缓存 -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg ref="jdkredisTemplate" />
</bean>
<bean id="topicContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer" destroy-method="destroy">
<property name="connectionFactory" ref="redisConnectionFactory"/>
<property name="messageListeners">
<map>
<entry key-ref="sub">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="dddchannel"/>
</bean>
</entry>
<entry key-ref="sub2">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="dddchannel"/>
</bean>
</entry>
<entry key-ref="sub3">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="cccchannel"/>
</bean>
</entry>
</map>
</property>
</bean>
Spring RedisTemplate操作-xml配置(1)的更多相关文章
- Spring IOC-基于XML配置的容器
Spring IOC-基于XML配置的容器 我们先分析一下AbstractXmlApplicationContext这个容器的加载过程. AbstractXmlApplicationContext的老 ...
- Spring 入门 web.xml配置详解
Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...
- spring之pom.xml配置
spring之pom.xml配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- 这一次搞懂Spring Web零xml配置原理以及父子容器关系
前言 在使用Spring和SpringMVC的老版本进行开发时,我们需要配置很多的xml文件,非常的繁琐,总是让用户自行选择配置也是非常不好的.基于约定大于配置的规定,Spring提供了很多注解帮助我 ...
- Spring Ioc容器xml配置
Spring Ioc容器xml配置基本结构: <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- Spring 使用AOP——xml配置
目录 AOP介绍 Spring进行2种实现AOP的方式 导入jar包 基于schema-based方式实现AOP 创建前置通知 创建后置通知 修改Spring配置文件 基于schema-based方式 ...
- Spring AOP之xml 配置实现
首先这个配置模式估计现在已经不用了,因为我在我们公司的项目里面并没有看到这么配置AOP相关的东西.不过,这个就和学习spring的控制反转(IOC)和依赖注入(DI)一样,刚刚开始的时候,都是从简单的 ...
- 关于Spring中applicationContext.xml配置错误“org/springframework/transaction/interceptor/TransactionInterceptor”的问题解决
问题描述: 在配置spring的applicationContext.xml中的默认事务管理器的时候可能会出现这样的错误: Error occured processing XML 'org/spri ...
- Spring学习之xml配置Bean总结
学习Spring时,我用的是Maven来管理jar包,先看看maven的pom.xml: pom.xml <project xmlns="http://maven.apache.org ...
随机推荐
- Jenkins 构建运行java程序
我们将在Jenkins建立执行一个简单的 HelloWorld 应用程序,构建和运行Java程序.打开网址:http://localhost:8080/jenkins 第1步- 转到Jenkins 仪 ...
- Unity3d-通过简单示例来理解Time.deltaTime
转载文章: Unity3d-通过简单示例来理解Time.deltaTime 2018年04月21日 18:04:14 Black_Window 阅读数:926 标签: UnityTime 更多 个人分 ...
- 第十六次ScrumMeeting博客
第十六次ScrumMeeting博客 本次会议于12月5日(二)22时整在3公寓725房间召开,持续20分钟. 与会人员:刘畅.张安澜.赵奕.方科栋. 1. 每个人的工作(有Issue的内容和链接): ...
- SpringMVC 之 @ResponseBody 和 @RequestBody
前后端进行数据交互的时候,规定数据交互的格式,使数据交互规范而统一,是极为重要的事.一般而言,我们会采用 JSON 进行数据交互.本文暂不讨论如何 JSON 的格式规范,而是解析一下如何在 Sprin ...
- node 随便升级到最新版本的遭遇
将node 升级到最新版本后,创建一个RN新项目,执行:react-native init AwesomeProject 遇到: error An unexpected error occurred ...
- hexo发文章
http://blog.csdn.net/qq_36099238/article/details/54576089
- Alpha版本项目展示要求(加入模板)
Alpha版本展示的时间暂定为11月17日课上,提前到13:00开始.如有变动,另行通知. Alpha版本项目展示要求如下: 不得使用PPT,展示所用的资料必须发表在博客上. 现场演示你们发布的软件. ...
- SCRUM 12.09 软件工程第二周计划
第二轮迭代的第二周开始了,上一周我们进行了对代码优化的探索与自我审查. 本周,我们有以下两点目标要实现: 1.对客户端进行优化. 2.网络爬虫爬取美团外卖. 客户端优化主要开发人员:高雅智.牛强.彭林 ...
- linux下php环境的装配以及php storm的链接
linux下php环境的装配以及php storm的链接 本次安装在deepin系统下完成 一.安装LAMP组合 Linux+Apache+Mysql+php 直接命令 sudo apt-get in ...
- _stdcall 和 _cdecl
今天遇到一个问题用C++编写一个动态链接库生成的文件为dll.dll,用在visual stdio 2010调用这个dll 调用形式:[DllImport("dll.dll")] ...