title: Using AspectJ LTW to allow spring proxy functionalty on self-invocation of non-public methods and related considerations
body: <p>I have seen numerous examples of Spring functionality related to <code>@Cacheable</code>, <code>@Transactional</code>, <code>@Async</code>, etc. where the same options are reiterated every time:</p>
  
  <ol>
  <li><p>Self invocation made through a proxy object gotten through either the <code>ApplicationContext.getBean(MyService.class)</code> or an autowired <code>MyService.class</code> proxy object in addition to <code>@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS)</code>,</p></li>
  <li><p>Relocating the target method to a separate <code>@Service</code> class,</p></li>
  <li><p>Using AspectJ load-time weaving.</p></li>
  </ol>
  
  <p>While the first two approaches are usually fine, there are times when we need to attach the functionality of the above three (and other) annotations to private methods, whether it be for code clarity, design, or other reasons.</p>
  
  <hr>
  
  <p>There are many example of the first two approaches, but very few of the last. As I understand, due to the nature of AspectJ LTW, by default it is mutually exclusive with the usual Spring AOP behaviour that enables the <code>@Cacheable</code>, etc. behaviour without much hassle. My questions are as follows:</p>
  
  <ol>
  <li><p>Are there any decent examples on enabling the above behaviour usually done with the first two options using AspectJ LTW?</p></li>
  <li><p>Is there a way to enable AspectJ LTW selectively, e.g. not for <code>@Async</code> and <code>@Transactional</code> but just <code>@Cacheable</code>? An example use case of this would perhaps be: due to a team's design, all cacheable methods (some of which may be private) should be located in a facade class which calls private methods that perform heavy calculations, but might update some state (i.e. <code>'last-queried-at: #'</code>) before returning to the external called.</p></li>
  </ol>
  
  <p>This question is from the viewpoint of a <code>spring-boot</code> user, but I believe it applies generally to Spring AOP and AspectJ LTW. Please correct me if there are special considerations needed in this case.</p>