spring aop aspectJ 使用XML配置AOP,只增加了一个切入点,但同一个切入方法执行二次的问题
Spring AOP XML配置文件:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
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/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<bean id="userManager" class="org.drsoft.business.UserManagerImpl">
</bean>
<aop:config>
<aop:pointcut expression="execution(public * org.drsoft.business.*.* (..))" id="allBefore"/>
<aop:aspect id="xmlAspect" ref="xmlAspect">
<aop:before method="BeforeLog" pointcut-ref="allBefore"/>
</aop:aspect>
</aop:config>
<bean id="xmlAspect" class="org.drsoft.aop.XMLAspect"/>
<bean
class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
</bean>
切面类:
package org.drsoft.aop;
public class XMLAspect {
public void BeforeLog() {
System.out.println("XMLAspect BeforeLog Time=" + System.currentTimeMillis());
}
}
Main方法:
package org.drsoft;
import org.drsoft.business.UserManager;
import org.drsoft.utils.SpringUtils;
public class SpringAOPXMLMain {
public static void main(String[] args) {
UserManager userManager = SpringUtils.getBean("userManager", UserManager.class);
userManager.signUser();
}
}
输出结果:
XMLAspect BeforeLog Time=1485916445019
XMLAspect BeforeLog Time=1485916480819
UserManagerImpl signUser Timestamp=1485916483706