0

I have a Spring / Hibernate application. Custom type created by Hibernate needs Spring context, so I use Spring Aspects to provide it.

@Configurable(preConstruction = true)
public class EncryptedStringUserType implements EnhancedUserType {
...

@EnableSpringConfigured
@EnableLoadTimeWeaving
public class RootConfiguration {
...

After adding Spring Security, I got number of messages in stderr like this:

[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]

Is it possible to specify packages of classes that should be weaved and avoid trying to weaving other ones?

SOLUTION

Put META-INF/aop.xml to resources root and exclude unnecessary packages:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver>
        <exclude within="org.springframework.security.config.annotation.authentication.configurers.ldap.*"/>
        <exclude within="org.springframework.security.config.annotation.web.configurers.openid.*"/>
    </weaver>
</aspectj>
Marboni
  • 2,399
  • 3
  • 25
  • 42
  • Maybe not the answer for your question but seems `@Configuration` missing for `RootConfiguration` class. – Efe Kahraman Aug 24 '15 at 06:18
  • It's loaded to the context straightly, `applicationContext.register(RootConfiguration.class);`, so no need in annotation. Thank you for comment. – Marboni Aug 25 '15 at 12:34

1 Answers1

2

You can limit the scope of weaving by adding a <include within="your.package.here.*"/> tag to the META-INF/aop.xml file in your classpath. Here's a full example of META-INF/aop.xml taken from the Spring documentation:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>

    <weaver>
        <!-- only weave classes in our application-specific packages -->
        <include within="foo.*"/>
    </weaver>

    <aspects>
        <!-- weave in just this aspect -->
        <aspect name="foo.ProfilingAspect"/>
    </aspects>

</aspectj>
heenenee
  • 19,914
  • 1
  • 60
  • 86
  • What aspect name should I specify if I want to weave only classes annotated with `@Configurable`? – Marboni Aug 21 '15 at 07:47
  • I believe this would work: ``. The docs for `META-INF/aop.xml` are here: http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html – heenenee Aug 21 '15 at 13:25
  • Unfortunately, it doesn't - I still see these messages. – Marboni Aug 23 '15 at 20:20
  • @Marboni are you sure that your `aop.xml` is being picked up? Like if you put invalid content in your `aop.xml`, do you get an error? – heenenee Aug 24 '15 at 20:24
  • 1
    Thank you, @heenenee, you are right. META-INF was not in the resources root. Not it works fine. – Marboni Aug 25 '15 at 08:37