Commit 721e1946 by java-李谡

添加redis依赖

parent 459ffb43
redis.host=106.75.105.96
redis.port=7211
redis.auth=bbdtek!@#2018
redis.maxTotal=100
redis.maxIdle=20
redis.maxWaitMillis=10000
redis.testOnBorrow=true
redis.testOnReturn=true
redis.dbIndex=3
\ No newline at end of file
......@@ -32,6 +32,7 @@
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:ejweb.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>
......@@ -141,4 +142,59 @@
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
</bean>
<!--设置jedisPool链接池的配置-->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.maxTotal}"/>
<property name="maxIdle" value="${redis.maxIdle}"/>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
<property name="testOnBorrow" value="${redis.testOnBorrow}"/>
<property name="testOnReturn" value="${redis.testOnReturn}"/>
</bean>
<!--redis链接密码-->
<bean id="redisPassword" class="org.springframework.data.redis.connection.RedisPassword">
<constructor-arg name="thePassword" value="${redis.auth}"></constructor-arg>
</bean>
<!--spring-data-redis2.0以上的配置-->
<bean id="redisStandaloneConfiguration"
class="org.springframework.data.redis.connection.RedisStandaloneConfiguration">
<property name="hostName" value="${redis.host}"/>
<property name="port" value="${redis.port}"/>
<property name="password" ref="redisPassword"/>
<property name="database" value="${redis.dbIndex}"/>
</bean>
<!--配置jedis链接工厂 spring-data-redis2.0中
建议改为构造器传入一个RedisStandaloneConfiguration 单机
RedisSentinelConfiguration 主从复制
RedisClusterConfiguration 集群-->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<!--spring-data-redis2.0以上建议获取的方式-->
<constructor-arg name="standaloneConfig" ref="redisStandaloneConfiguration"></constructor-arg>
</bean>
<!--手动设置 key 与 value的序列化方式-->
<bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<bean id="valueSerializer" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
<!--配置jedis模板 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
</bean>
<!--也可以StringRedisTemplate 专注于String的操作 -->
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<!--<property name="connectionFactory" ref="jedisConnectionFactory"></property>-->
<!--在StringRedisTemplate与redisTemplate不同,可以直接造构造器中传入ConnectionFactory-->
<constructor-arg name="connectionFactory" ref="jedisConnectionFactory"></constructor-arg>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
</bean>
</beans>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment