在SpringMVC 中无法进入方法拦截器

南窗寄傲琴书消忧 2017-04-27 05:01:21
配置文件redis.xml
<?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>


MethodCacheInterceptor.java 总是无法进入此方法中,不知道是否哪里配置错误了
    @Override
public Object invoke(MethodInvocation invocation) throws Throwable {
//缓存处理。。。。

//调用目标方法
Object rval = invocation.proceed();
//调用目标方法之后执行的动作
System.out.println("comming..........");
return rval;
}

Service
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);
}

ServiceImpl

@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);
}
}


在做查询的时候 能查出数据库的内容,但是无法对service中的各种方法进行拦截,无法进入intercepter,不知道是不是要对serviceImpl代理,可是MVC自动注解中找不到service的bean,



...全文
164 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧