title: Spring Aspects: specify which packages to weave
body: <p>I have a Spring / Hibernate application. Custom type created by Hibernate needs Spring context, so I use Spring Aspects to provide it.</p>
  
  <pre><code>@Configurable(preConstruction = true)
  public class EncryptedStringUserType implements EnhancedUserType {
  ...
  
  @EnableSpringConfigured
  @EnableLoadTimeWeaving
  public class RootConfiguration {
  ...
  </code></pre>
  
  <p>After adding Spring Security, I got number of messages in stderr like this:</p>
  
  <pre><code>[AppClassLoader@14dad5dc] error can't determine implemented interfaces of missing type org.springframework.security.ldap.authentication.LdapAuthenticationProvider
  when weaving type org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer
  when weaving classes 
  when weaving 
   [Xlint:cantFindType]
  </code></pre>
  
  <p>Is it possible to specify packages of classes that should be weaved and avoid trying to weaving other ones?</p>
  
  <h2>SOLUTION</h2>
  
  <p>Put META-INF/aop.xml to resources root and exclude unnecessary packages:</p>
  
  <pre><code>&lt;!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"&gt;
  &lt;aspectj&gt;
      &lt;weaver&gt;
          &lt;exclude within="org.springframework.security.config.annotation.authentication.configurers.ldap.*"/&gt;
          &lt;exclude within="org.springframework.security.config.annotation.web.configurers.openid.*"/&gt;
      &lt;/weaver&gt;
  &lt;/aspectj&gt;
  </code></pre>