li3807 2017-02-01 05:51 采纳率: 0%
浏览 2017

spring aop aspectJ 使用XML配置AOP,但同一个切入方法执行二次的问题

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

  • 写回答

2条回答 默认 最新

  • li3807 2017-02-01 06:03
    关注

    代码调整,输出了方法名称,根据输出结果,发现是同一个方法执行了多次
    public void BeforeLog(JoinPoint joinPoint) {
    System.out.println("XMLAspect BeforeLog Time=" + System.currentTimeMillis() + "\tName="
    + joinPoint.getSignature().getName());
    }

    输出结果:
    XMLAspect BeforeLog Time=1485928792439  Name=signUser
    

    XMLAspect BeforeLog Time=1485928792441 Name=signUser
    UserManagerImpl signUser Timestamp=1485928792441

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记