Results 1 to 3 of 3

Thread: Pointcuts on specific subclasses?

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Code:
    pointcut="execution(* web.controller.*.handleRequest(..)) && target(web.controller.ConcreteController1)"
    Something like that should do it.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Excellent! Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •