0

我有一个 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>
4

1 回答 1

2

您可以通过在类路径中的文件中添加<include within="your.package.here.*"/>标签来限制编织的范围。这是取自Spring 文档META-INF/aop.xml的完整示例: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>
于 2015-08-20T15:57:32.350 回答