81,122
社区成员




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