项目搭建连接redis

来源:互联网 发布:软件详细设计模板 java 编辑:程序博客网 时间:2024/06/17 12:08

service-beans.xml的内容:

<?xml version="1.0" encoding="GB2312"?><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"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:util="http://www.springframework.org/schema/util"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="         http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context-3.0.xsd        http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc.xsd        http://www.springframework.org/schema/util        http://www.springframework.org/schema/util/spring-util-3.0.xsd        http://www.springframework.org/schema/aop        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">            <context:component-scan base-package="com.hundsun"/><context:annotation-config /><!--定时任务 --> <import resource="compet-front-timer-task.xml" /><bean id="propertyConfigurerForProject2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">        <property name="order" value="2" />        <property name="ignoreUnresolvablePlaceholders" value="true" />        <property name="locations">          <list>            <value>classpath:conf/server.properties</value>            <value>classpath:conf/redis.properties</value>          </list>        </property>    </bean><!-- 切面 -->    <bean id="serviceInterceptor" class="com.hundsun.front.compet.aop.ServiceInterceptor"/><aop:config proxy-target-class="true">        <!-- ### 切点 ### -->        <aop:pointcut id="businessService" expression="execution(* com.hundsun.compet.biz.service.impl.*.*(..))" />         <!-- Debug方法入参 ,返回值 -逻辑织入 -->        <aop:aspect id="serviceAspect" ref="serviceInterceptor">           <aop:before pointcut-ref="businessService" method="doBeforeService"/>            <!-- Debug Method output Object -->            <aop:around pointcut-ref="businessService" method="doReturnValue"/>        </aop:aspect>    </aop:config>    <!-- redis 操作 配置 --><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxTotal" value="${redis.maxTotal}"></property><property name="maxIdle" value="${redis.maxIdle}"></property><property name="maxWaitMillis" value="${redis.maxWaitMillis}"></property><property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"></property><property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"></property><property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"></property></bean><context:property-placeholder location="classpath*:conf/redis.properties"ignore-unresolvable="true" /><bean id="connectionFactory"class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"><property name="poolConfig" ref="jedisPoolConfig" /><property name="hostName" value="${redis.host}"></property><property name="port" value="${redis.port}" /><property name="password" value="${redis.password}" /><property name="timeout" value="${redis.timeout}" /></bean><bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"><property name="connectionFactory" ref="connectionFactory" /><property name="keySerializer"><beanclass="org.springframework.data.redis.serializer.StringRedisSerializer"></bean></property><property name="valueSerializer"><beanclass="org.springframework.data.redis.serializer.StringRedisSerializer"></bean></property></bean><bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"><property name="connectionFactory" ref="connectionFactory" /></bean><bean class="com.hundsun.front.init.cache.CacheConfig"/></beans>


使用的时候:

引入包:

import org.springframework.data.redis.core.StringRedisTemplate;

使用:

@Autowired

private StringRedisTemplate stringRedisTemplate;


StringRedisTemplate常用操作

参考:

http://blog.csdn.net/u011911084/article/details/53435172