title: Enable Spring AOP or AspectJ
body: <p>This is following on from this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/9633840/spring-autowired-bean-for-aspect-aspect-is-null/9658819#9658819">Spring autowired bean for @Aspect aspect is null</a></p>
  
  <p>My initial understanding was that when using Spring AOP, classes annotated with @Aspect are created as spring managed beans, so dependency injection would work as normal.  However it seems that an object with the @Aspect annotation is created as a singleton outside the spring container, hence me having to configure it in XML like so in order to enable it as a spring managed bean:</p>
  
  <pre><code>&lt;bean id="aspect" class="com.mysite.aspect" factory-method="aspectOf" /&gt;
  </code></pre>
  
  <p>This has now completely confused me.  I thought the following configuration would use spring AOP:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.mysite.aspectPackage"/&gt;
  &lt;aop:aspectj-autoproxy/&gt;
  </code></pre>
  
  <p>So it would scan for @Aspect annotations using component-scan creating aspect beans, and then autoproxy would create a beanPostProcessor which proxies all beans within my context with the appropriate advice.  I then thought to enable aspectJ I would need a completely different XML configuration (which incidentally I can't seem to find an example of in the documentation).  It would be this configuration that uses aspectJ to create aspects that would be outside of my container or which work by manipulating bytecode rather than proxying.</p>
  
  <p><b>Note</b><br/>
  This is not a question on the difference between spring AOP and aspect J, this is well articulated here:</p>
  
  <p><a href="https://stackoverflow.com/questions/1606559/spring-aop-vs-aspectj">Spring AOP vs AspectJ</a></p>