【问题标题】:Spring Aspects: specify which packages to weaveSpring Aspects:指定要编织的包
【发布时间】:2015-08-17 21:45:52
【问题描述】:

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

【问题讨论】:

  • 也许不是您问题的答案,但似乎 @Configuration 缺少 RootConfiguration 类。
  • 直接加载到上下文中,applicationContext.register(RootConfiguration.class);,所以不需要注解。感谢您的评论。

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


【解决方案1】:

您可以通过在类路径中的META-INF/aop.xml 文件中添加&lt;include within="your.package.here.*"/&gt; 标记来限制编织范围。下面是来自Spring documentationMETA-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>

【讨论】:

  • 如果我只想编织带有 @Configurable 注释的类,我应该指定什么方面名称?
  • 我相信这会起作用:&lt;include within="@org.springframework.beans.factory.annotation.Configurable foo.*"/&gt;META-INF/aop.xml 的文档在这里:eclipse.org/aspectj/doc/released/devguide/…
  • 不幸的是,它没有 - 我仍然看到这些消息。
  • @Marboni 你确定你的aop.xml 正在被取走吗?比如如果你在aop.xml 中放入了无效的内容,你会收到错误吗?
  • 谢谢你,@heeneee,你是对的。 META-INF 不在资源根目录中。不是它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-18
  • 1970-01-01
相关资源
最近更新 更多