title: Intercept private methods with Spring and AspectJ
body: <p>I am trying to execute code before a private method using AspectJ's load-time-weaving with Spring-Boot and annotation-based configuration and I'm pulling my hair out trying to figure out why my aspect is not being invoked.</p>
  
  <p>My simple aspect is as follows:</p>
  
  <pre><code>@Aspect
  public class LoggingAspect {
  
    private static Logger log = LoggerFactory.getLogger(LoggingAspect.class);
  
    @Before("execution(private * com.mycompany.MyServiceWithPrivateMethods.*(..))")
    public void privateAspect() {
      log.warn("#### Private method aspect invoked!");
    }
  
  }
  </code></pre>
  
  <p>I also have the <code>@EnableLoadTimeWeaving</code> annotation on my Spring configuration class and the following in my META-INF/aop.xml:
  </p>
  
  <pre><code>&lt;aspectj&gt;    
      &lt;weaver options="-verbose"&gt;
          &lt;!-- only weave classes in our application-specific packages --&gt;
          &lt;include within="com.mycompany.*"/&gt;
      &lt;/weaver&gt;
  
      &lt;aspects&gt;
          &lt;!-- weave in just this aspect --&gt;
          &lt;aspect name="com.mycompany.LoggingAspect"/&gt;
      &lt;/aspects&gt;    
  &lt;/aspectj&gt;
  </code></pre>
  
  <p>Lastly, I am also starting my application with the <code>-javaagent:/path/to/spring-instrument.jar</code> option, per the docs.  I also have the required jars on my classpath (<code>spring-aop</code> and <code>aspectjweaver</code>) as also mentioned in the Spring docs.</p>
  
  <p>Is this even possible? There is a 'limitation' listed in the AspectJ docs that states <code>Privileged aspects are not supported by the annotation style.</code> located <a href="http://eclipse.org/aspectj/doc/next/adk15notebook/ataspectj-aspects.html" rel="nofollow">here</a>, however <a href="http://forum.spring.io/forum/spring-projects/aop/44790-spring-aop-caching-with-aspectj-weaving-is-not-happening" rel="nofollow">this</a> older post in the Spring Forum seems to indicate that it is indeed possible.  </p>