Spring Advisor指向的Advice没有执行是为什么

Ericsson5 云南大学 2015-07-14 03:55:10
Beans配置文件

<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="sellerTarget" class="com.hand.china.staticmethodmatcher.Seller"></bean>
<bean id="waiterTarget" class="com.hand.china.staticmethodmatcher.Waiter"></bean>

<bean id="greetingBeforeAdvice" class="com.hand.china.staticmethodmatcher.GreetingBeforeAdvice"></bean>
<bean id="staticPointcutAdvisor"
class="com.hand.china.staticmethodmatcher.StaticPointcutAdvisor"
p:advice-ref="greetingBeforeAdvice"></bean>

<bean id="parent" class="org.springframework.aop.framework.ProxyFactoryBean"
p:interceptorNames="staticPointcutAdvisor" p:proxyTargetClass="true"
abstract="true" />
<bean id="waiter" p:target-ref="waiterTarget"
class="org.springframework.aop.framework.ProxyFactoryBean"
p:interceptorNames="staticPointcutAdvisor" p:proxyTargetClass="true" />
<bean id="seller" parent="parent" p:target-ref="sellerTarget" />
</beans>


Advisor代码

package com.hand.china.staticmethodmatcher;

import java.lang.reflect.Method;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;

public class StaticPointcutAdvisor extends StaticMethodMatcherPointcutAdvisor {

/**
*
*/
private static final long serialVersionUID = 4778452700966282045L;

@Override
public boolean matches(Method arg0, Class<?> arg1) {
// TODO Auto-generated method stub
return "GreeTo".equals(arg0.getName());
}

@Override
public ClassFilter getClassFilter() {
// TODO Auto-generated method stub
return new ClassFilter() {

@Override
public boolean matches(Class<?> arg0) {
// TODO Auto-generated method stub
return Waiter.class.isAssignableFrom(arg0);
}
};
}

}


Advice代码

package com.hand.china.staticmethodmatcher;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class GreetingBeforeAdvice implements MethodBeforeAdvice {

@Override
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
// TODO Auto-generated method stub
String client = (String) arg1[0];
System.out.println("AOP: " + client);
}

}

...全文
73 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-07-14 03:55
社区公告
暂无公告