如何在基于 Spring 的应用程序上使用所有 AspectJ 切入点指示符?

How to use all AspectJ pointcut designators on a Spring based application?

我有一个由 Maven 管理的 Spring 项目。而不是像下面这样使用 execution 切入点指示符:

@Before("execution(* my.app.TestUtil.myStaticClass(..))")
public void logBeforeTestUtil(JoinPoint joinPoint) {
    System.out.println("*** hijacked : " + joinPoint.getSignature().getName());
}

我想使用 call 切入点指示符,例如:

@Before("call(* my.app.TestUtil.myStaticClass(..))")
public void logBeforeTestUtil(JoinPoint joinPoint) {
    System.out.println("*** hijacked : " + joinPoint.getSignature().getName());
}

但是,我的 IDE (IntelliJ) 告诉我 call pointcut designator isn't supported by Spring,即使我在 pom.xml.

中删除了 spring-aop

我想提一下上面的示例,其中 execution 切入点指示符正在工作并且 Spring AOP does not supports all AspectJ pointcut designators.

This answer 展示了如何在不使用 Spring 的情况下使用加载时间编织。我想知道我们是否可以在没有 Spring AOP 的情况下使用 Spring + AspectJ。如果可以,怎么做?

编辑:添加 pom.xml 和上下文配置文件

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.app</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <spring.version>4.3.4.RELEASE</spring.version>
        <jackson.version>2.7.3</jackson.version>
        <aspectj.version>1.8.4</aspectj.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <aspectj.version>1.8.4</aspectj.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-aop</artifactId>-->
            <!--<version>${spring.version}</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-instrument</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
</project>

应用-context.xml

package my.app;

import org.springframework.context.annotation.*;

@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class AppConfig {
}

META-INF/aop.xml

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver>
        <include within="my.app.utils.*"/>
        <include within="my.app.aspect.*"/>
    </weaver>
    <aspects>
        <aspect name="my.app.aspect.LoggingAspect" />
    </aspects>
</aspectj>

对于execution,必须告知调用代码。对于 call,必须告知 调用 代码。 调用代码是否在my.app.utils.*my.app.aspect.*范围内?这些是您配置编织器要包含的唯一包。如果调用者来自 org.springframework... 或您应用程序的其他部分,则不会被告知。

转换为之前评论的答案。