voluminat0
voluminat0

Reputation: 906

Spring AOP pointcut not triggering

For some reason, my pointcut is not triggered. Note: I am using spring-style aspects, not AspectJ style.

XML snippet

<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>

Class defined by my 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();
    }

}

Am I missing something?

Upvotes: 0

Views: 336

Answers (1)

Zoran Regvart
Zoran Regvart

Reputation: 4690

Most probably invocation of handleRequestInternal method is not done across bean boundaries, but from the bean itself. I guess you're using AbstractController as a base for your controllers, and you can see that handleRequest method is calling handleRequestInternal directly.

You cannot instrument that code without using aspect compiler and change the class bytecode. And you probably don't want to do that with library code (AbstractController).

Upvotes: 1

Related Questions