Spring Aspects:指定要编织的包

时间:2015-08-17 21:45:53

标签: spring spring-security spring-aop spring-aspects

我有一个Spring / Hibernate应用程序。 Hibernate创建的自定义类型需要Spring上下文,所以我使用Spring Aspects来提供它。

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

@EnableSpringConfigured
@EnableLoadTimeWeaving
public class RootConfiguration {
...

添加Spring Security后,我在stderr中收到了许多消息:

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

是否可以指定应编织的类包,避免尝试编织其他类?

将META-INF / aop.xml放到资源根目录并排除不必要的包:

<!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>

1 个答案:

答案 0 :(得分:2)

您可以通过向类路径中的<include within="your.package.here.*"/>文件添加META-INF/aop.xml标记来限制编织范围。以下是从Spring documentation获取的META-INF/aop.xml的完整示例:

<!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>