我需要哪个jar使用Spring AOP AspectJ Annotation?

问题描述 投票:1回答:2

我是春天的新手。我试图使用Spring AOP注释,如下面的代码。

@Aspect
public class A {
    @Pointcut("execution(* Operation.*(..))")
    public void b(){} 

    @Before("b()") 
    public void c(JoinPoint jp)
    {
        System.out.println("a");
    }
}

在我引用的库中,我放了所有的spring jar(aop,core,aspects,beans,context,instrument,jdbc,jms,web,webmvc等)

我发现另一个jar aspectj-1.9.3.jar并在我的eclipse中将它添加到我的库中。但是,我无法导入org.aspectj.lang.*(我需要)。我的Eclipse似乎找不到它。

我找到了合适的罐子吗? (所以问题还有别的吗?)或者我需要另一个罐子吗?我试图不使用Maven。

java spring aspectj spring-aop
2个回答
2
投票
org.aspectj.lang.joinpoint is part of the aspectj tool library. 

将其添加到Maven:

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjtools</artifactId>
    <version>1.8.9</version>
</dependency>

1
投票

下面我提到了轻量级罐子,因为aspectjtools太大了。

compile group: 'org.springframework', name: 'spring-aop', version: '5.1.5.RELEASE'
compile group: 'aspectj', name: 'aspectjweaver', version: '1.5.4'

罐子大小:

aspectjtools 1.9.2: 13.2 MB // too big

 aspectjweaver 1.9.2: 2.0 MB,  // too small as compared to aspectjtools jar
 spring AOP 5.1.5: 360 KB

所以,避免使用aspectjtools jar,因为它太大了。

© www.soinside.com 2019 - 2024. All rights reserved.