5,657
社区成员
发帖
与我相关
我的任务
分享<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:redis.properties"/>
</bean>
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" >
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean >
<!-- redis服务器中心 -->
<bean id="connectionFactory" 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" class="org.springframework.data.redis.core.RedisTemplate" >
<property name="connectionFactory" ref="connectionFactory" />
<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 >
<!-- 拦截处理-->
<bean id="methodCacheInterceptor" class="com.xyb.interceptor.MethodCacheInterceptor" >
<property name="redisUtil" ref="redisUtil" />
</bean >
<bean id="redisUtil" class="com.xyb.utils.cache.RedisUtil" >
<property name="redisTemplate" ref="redisTemplate" />
</bean >
<!--拦截-->
<bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor" >
<property name="advice" >
<ref bean="methodCacheInterceptor" />
</property>
<property name="patterns" >
<list>
<!--
<value>.*get.*</value>
-->
<value>com.xyb.service.impl.*</value >
</list>
</property>
</bean >
</beans> @Override
public Object invoke(MethodInvocation invocation) throws Throwable {
//缓存处理。。。。
//调用目标方法
Object rval = invocation.proceed();
//调用目标方法之后执行的动作
System.out.println("comming..........");
return rval;
}public interface AticleService {
//查询 id 所有
Aticle getAticleById(int id);
List<Aticle> getAticleAll();
List<Aticle> getAticleByType(int mtype);
List<Aticle> selectIndex();
//增删改
int addAticle(Aticle aticle);
int deleteAticle(Aticle aticle);
int updateAticle(Aticle aticle);
int deleteAticleById(int id);
}
@Service("aticleService")
@Transactional(rollbackFor = Exception.class)
public class AticleServiceIml implements AticleService{
@Resource(name="aticleDao")
private AticleDao aticleDao;
public Aticle getAticleById(int id) {
return aticleDao.selectAticleById(id);
}
public List<Aticle> getAticleAll() {
return aticleDao.selectAticleAll();
}
public List<Aticle> getAticleByType(int mtype) {
return aticleDao.selectAticleByType(mtype);
}
public List<Aticle> selectIndex() {
return aticleDao.selectIndex();
}
public int addAticle(Aticle aticle) {
return aticleDao.addAticle(aticle);
}
public int deleteAticle(Aticle aticle) {
return aticleDao.deleteAticle(aticle);
}
public int updateAticle(Aticle aticle) {
return aticleDao.updateAticle(aticle);
}
public int deleteAticleById(int id) {
return aticleDao.deleteAticleById(id);
}
}