<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 配置redis连接池对象 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 最大空闲数 -->
<property name="maxIdle" value="50"></property>
<!-- 最大连接数 -->
<property name="maxTotal" value="100"></property>
<!-- 最大等待时间 -->
<property name="maxWaitMillis" value="20000"></property>
</bean>
<!-- 配置redis连接工厂 -->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<!-- 连接池配置 -->
<property name="poolConfig" ref="poolConfig"></property>
<!-- 连接主机 -->
<property name="hostName" ref="192.168.101.128"></property>
<!-- 端口 -->
<property name="port" ref="6379"></property>
<!-- 密码 -->
<property name="password" ref="root"></property>
</bean>
<!--
配置序列化的方式 搜索*RedisSerializer 有很多种序列化的方式
-->
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
<!-- 配置redis模板对象
模板的使用
Student的实体类要事项接口 Serializable
Student stu = new Student(10,"小红",19,new Date());
template.opsForValue().set("student",stu);
-->
<bean class="org.springframework.data.redis.core.RedisTemplate">
<!-- 配置连接工厂 -->
<property name="connectionFactory" ref="connectionFactory"></property>
<!-- 修改键的序列化器 -->
<property name="keySerializer" ref="stringRedisSerializer"></property>
<!-- 修改值的序列化器 -->
<property name="valueSerializer" ref="stringRedisSerializer"></property>
</bean>
</beans>
redis结合spring的配置文件
最新推荐文章于 2024-05-11 17:12:48 发布