1. 程式人生 > >JavaEE_Spring_Aspect無法切入Controller層

JavaEE_Spring_Aspect無法切入Controller層

com ets nature tor factor static gets npoi true

切入的類和被切入的類必須是被spring管理的(springIOC),如果是自己new 出來的,切入無效,所以最好把它放在dispatcher-servlet.xml文件中。

//切入類:
@Aspect
@Component
public class LoggingAspect {
    private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);

    @After("execution(* com.hanming.oa.controller..*.*(..))")
    public void afterMethod(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        String username = (String) SecurityUtils.getSubject().getSession().getAttribute("username");
        logger.info(username + " ================= 執行 ================= " + methodName);
    }
}
//使 Aspectj 註解起作用:自動匹配的類生成代理對象
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>

JavaEE_Spring_Aspect無法切入Controller層