Announcement Announcement Module
Collapse
No announcement yet.
Pointcuts on specific subclasses? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointcuts on specific subclasses?

    Dear Spring Forum,

    I have some Spring MVC controllers subclassing from an abstract controller:
    Code:
    public abstract class AbstractController implements Controller {
        @Override
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { ... }
    }
    
    public class ConcreteController1 extends AbstractController { ... }
    public class ConcreteController2 extends AbstractController { ... }
    I am trying to add some advice when the handleRequest() method of a specific subclass executes:
    Code:
    <aop:aspect id="viewSwitchAspect" ref="viewSwitchAdvice">
        <aop:before method="assignView"
            pointcut="execution(* web.controller.ConcreteController1.handleRequest(..))"/>
    </aop:aspect>
    This configuration does not cause the advice to be executed.

    But this advice does:
    Code:
    <aop:aspect id="viewSwitchAspect" ref="viewSwitchAdvice">
        <aop:before method="assignView"
            pointcut="execution(* web.controller.*.handleRequest(..))"/>
    </aop:aspect>
    My guess is that the reason is that the handleRequest() method is implemented in the abstract superclass. I don't want ConcreteController2 to receive this advice.

    How can I achieve this?

    Thanks,

    Stewart

  • #2
    Code:
    pointcut="execution(* web.controller.*.handleRequest(..)) && target(web.controller.ConcreteController1)"
    Something like that should do it.

    Comment


    • #3
      Excellent! Thank you.

      Comment

      Working...
      X