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

}

...全文
132 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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