哈儿将军,农村金融改革,三生有幸格格巫
<!-- redis客户端 --> <dependency> <groupid>redis.clients</groupid> <artifactid>jedis</artifactid> <version>2.9.0</version> </dependency> <!-- redis spring 基于注解配置 --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-redis</artifactid> <version>1.7.2.release</version> </dependency>
#redis地址 redis.host=127.0.0.1 #端口 redis.port=6379 # 密码,没有则可以不写 redis.pass=123456 redis.database=0 redis.maxidle=300 redis.maxwait=3000 redis.testonborrow=true
<!-- 加载redis配置文件,可以后面用,为了简单我用得默认配置 --> <context:property-placeholder location="classpath:/redis/redis-config.properties"/> <bean id="jedisfactory" class="org.springframework.data.redis.connection.jedis.jedisconnectionfactory"/> <!-- 操作模板 --> <bean id="jedistemplate" class="org.springframework.data.redis.core.redistemplate"> <property name="connectionfactory" ref="jedisfactory"/> <property name="keyserializer"> <bean class="org.springframework.data.redis.serializer.stringredisserializer"/> </property> <property name="valueserializer"> <bean class="org.springframework.data.redis.serializer.jdkserializationredisserializer"/> </property> </bean>
几个小插曲
1.在xml中引用外部xml文件
<import resource="spring-redis.xml"/> spring-redis.xml就是外部文件
2.解决一个xml中只能引入一个.properties文件的问题
在引用的时候,用如下写法
<context:property-placeholder ignore-unresolvable="true" location="classpath:first.properties" /> <context:property-placeholder ignore-unresolvable="true" location="classpath:second.properties" />
3. redis中要存入对象时,对象要实现serializable接口
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论