我有这样一个需要,我是想拦截所有类的所有方法,但是要屏蔽掉其中的一个类该怎么做。
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="securityHandler" class="com.bjsxt.spring.SecurityHandler"/>
<bean id="userManager" class="com.bjsxt.spring.UserManagerImpl"/>
<bean id="test" class="com.bjsxt.spring.ITestImpl"/>
<aop:config>
<aop:aspect id="security" ref="securityHandler">
<aop:pointcut id="allAddMethod" expression="execution(* *.*(..))"/>
<aop:after method="checkSecurity" pointcut-ref="allAddMethod"/>
</aop:aspect>
</aop:config>
</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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="securityHandler" class="com.bjsxt.spring.SecurityHandler"/>
<bean id="userManager" class="com.bjsxt.spring.UserManagerImpl"/>
<bean id="test" class="com.bjsxt.spring.ITestImpl"/>
<aop:config>
<aop:aspect id="security" ref="securityHandler">
<aop:pointcut id="allAddMethod" expression="execution(* *.*(..))"/>
<aop:after method="checkSecurity" pointcut-ref="allAddMethod"/>
</aop:aspect>
</aop:config>
</beans>
这样配置会拦截所有的方法,但是我想屏蔽掉其中一个类的所有方法不知道有什么好的方法嘛,希望高手指教
但是在Aspect中可以判断类名,如果是不想处理的类,直接返回public void checkSecurity(JoinPoint jp) {
String className = jp.getTarget().getClass().getName()
System.out.println();
if(className.equals(..)) {
return ;
}
}
public void checkSecurity(JoinPoint jp) {
String className = jp.getTarget().getClass().getName();
System.out.println(className );
if(className.equals(..)) {
return ;
}
}
execution(包名 类名.方法名(参数..)) 在这里配置你的切入点
将类名改为需要切入的类名就可以了。