Spring AspectJ loadtimeweaving没有被调用 [英] Spring AspectJ loadtimeweaving not invoked

查看:264
本文介绍了Spring AspectJ loadtimeweaving没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring AspectJ加载时织入配置正在构建和加载服务器,而没有任何错误,但是未调用该方面.

The Spring AspectJ loadtime weaving configuration is building and loading server without any errors, but the aspect is not getting invoked.

这是配置列表 1)JDK 8 2)服务器码头

Here is the list of configuration 1) JDK 8 2) Server Jetty

@Configuration
@ComponentScan(basePackages = {..})
@EnableSpringConfigured
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
@PropertySource(...)
@ImportResource(value = { "classpath:META-INF/aop.xml", ..})
class config {
...
}

aop.xml

<aspectj>     
      <weaver options="-Xlint:ignore -Xset:weaveJavaPackages=true -Xset:weaveJavaxPackages=true">
        <include within="com.proj.*"/>
        <include within="java.*"/>
        <include within="javax.*"/>
        <include within="org.springframework.*"/>
        <include within="org.aspectj.*"/>
    </weaver>
    <aspects>
        <aspect name="com.proj.SampleAspect"/>
    </aspects>
</aspectj>

还尝试了aop.xml中的选项

Have also tried with options in aop.xml

options="-XnoInline -verbose -showWeaveInfo -debug -Xlint:ignore -Xset:weaveJavaPackages=true -Xset:weaveJavaxPackages=true"

方面

@Component
@Aspect
public class SampleAspect {
    @Autowired
    private RequestContextFilter interceptRequestContext;

    @Around("@annotation(ExecuteByContext)")
    public Object interceptByContext(final ProceedingJoinPoint pjp) throws Throwable {
        if(SampleUtil.applyForRequest(interceptRequestContext.getRequestContext()) {
            LOGGER.info(String.format("Intercept context for method %s", pjp.getSignature().getName()));
            return null;
        }
        return pjp.proceed();
    }
}

注释

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExecuteByContext {

}

@Component
@Configurable
class TestClass implements ISomeInterface{

  ...
  @ExecuteByContext
  public void method() {
    ..
  }

  @ExecuteByContext
  private void method1() {
    ..
  }
}

使用MAVEN_OPTS设置启动Jetty服务器

Jetty server is started with MAVEN_OPTS setting

-javaagent:/path_to/.m2/repository/org/springframework/spring-instrument/4.2.0.RELEASE/spring-instrument-4.2.0.RELEASE.jar

-javaagent:/path_to/.m2/repository/org/springframework/spring-instrument/4.2.0.RELEASE/spring-instrument-4.2.0.RELEASE.jar

我的行家中有以下依赖项

I have the following dependency in my maven

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.2.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-instrument</artifactId>
</dependency>

没有调用SampleAspect.我有几种用@ExecuteByContext注释的方法(公共,私有和受保护).

The SampleAspect is not getting invoked. I have couple of methods (public, private and protected) annotated with @ExecuteByContext.

推荐答案

可能您的目标类不是直接在包com.proj中,而是在子包中.包含子包的语法为..*,而不仅仅是.*,即在您应具有的 aop.xml

Probably your target classes are not directly in package com.proj but in a subpackage. The syntax for including subpackages is ..*, not simply .*, i.e. in your aop.xml you should have

<include within="com.proj..*"/>

等等.

这篇关于Spring AspectJ loadtimeweaving没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆