簡體   English   中英

Spring AOP切入點不觸發

[英]Spring AOP pointcut not triggering

由於某些原因,我的切入點未觸發。 注意:我使用的是Spring樣式的方面,而不是AspectJ樣式。

XML片段

<bean id="authenticationAspect" class="ssel.banking.security.AuthenticationAspect" />

<aop:config>
    <aop:aspect ref="authenticationAspect">
        <aop:pointcut id="interceptControllerInvocation"
            expression="execution(* org.springframework.web.servlet.mvc.Controller+.handleRequestInternal(javax.servlet.http.HttpServletRequest, ..)) 
                                      and args(request, ..) 
                                      and target(controller)"/>

        <aop:around pointcut-ref="interceptControllerInvocation" 
            method="authenticationAdvice"/>
    </aop:aspect>
</aop:config>

我的bean定義的類

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class AuthenticationAspect {

    public ModelAndView authenticationAdvice(ProceedingJoinPoint pjp, HttpServletRequest request, Controller controller) throws Throwable{

        String URL = request.getRequestURL().toString();
        String viewName = URL.substring(0, URL.length() - 4);
        System.out.println(viewName);

        return (ModelAndView) pjp.proceed();
    }

}

我想念什么嗎?

最有可能不是跨bean邊界調用handleRequestInternal方法,而是從bean本身進行調用。 我想您正在使用AbstractController作為控制器的基礎,並且可以看到handleRequest方法直接調用handleRequestInternal。

如果不使用方面編譯器並更改類字節碼,則無法檢測該代碼。 而且您可能不想使用庫代碼(AbstractController)來做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM