Spring pointcut for abstract class' protected method
aspectj, java, spring, spring-aop
Solution
You should add a `+` sign after the abstract class.
So
"execution(* com.x.y.x.MyClass.myMethod(..))"
should look like:
"execution(* com.x.y.x.MyClass+.myMethod(..))"
↑
The `+` is about inheritance either extending the given class (`MyClass`) or implementing an interface.
Problem
I am using `Spring 3.2` and `AspectJ 1.7.1`. (It is not likely that I can upgrade to later versions in the near future.) I need to define a pointcut for a protected method in an abstract class. AFAIK I need `AspectJ` for methods that are not public, so I have only tried this with the (`AspectJ`) annotations: ``` package com.aspects; @Aspect public class Aspect{ @Before("execution(* com.x.y.x.MyClass.myMethod(..))") public void beforeAspect(){ //do something here } } ``` In my `beans.xml` I have: ``` <aop:aspectj-autoproxy /> <bean id="myAspect" class="com.aspects.Aspect"/> ``` I have checked and my `Aspect` class is created (constructor is getting called), no exception is being thrown when the application is launched. However I can not get the `beforeAspect` to be called. For public methods in non abstract classes this works. How can I make it work for protected method in abstract class?