IntelliJ IDEA의 샘플 프로젝트에서 AspectJ를 사용하려고합니다. 나는 Spring AOP에 대한 경험이있다. 그러나 이것은 AspectJ를 처음 사용하고 있으며, 동작시킬 수 없다. 여기에 설명 된대로 내가 할 노력하고 있어요IntelliJ IDEA + AspectJ
: https://www.jetbrains.com/help/idea/2017.1/aspectj.html
내 build.gradle :
apply plugin: 'java'
repositories
{
mavenCentral()
}
dependencies
{
compile "org.projectlombok:lombok:+"
compile "org.aspectj:aspectjrt:+"
compile "org.aspectj:aspectjweaver:+"
compile "org.aspectj:aspectjtools:+"
}
buildscript
{
repositories
{
maven
{
url "https://maven.eveoh.nl/content/repositories/releases"
}
}
dependencies
{
classpath "nl.eveoh:gradle-aspectj:+"
}
}
project.ext
{
aspectjVersion = '+'
}
apply plugin: 'aspectj'
내 측면 :
package aspects;
import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import java.util.Arrays;
@Aspect
@FieldDefaults(makeFinal = true)
public aspect LoggingAspect
{
Journal journal = Journal.INSTANCE;
pointcut all(ProceedingJoinPoint proceedingJoinPoint) : execution(* * set*(..));
around() : all(ProceedingJoinPoint proceedingJoinPoint)
{
System.out.println("asd");
}
@SneakyThrows
@Around("execution(* * repository.*.*(..))")
public Object log(ProceedingJoinPoint proceedingJoinPoint)
{
journal.write(proceedingJoinPoint.getThis().getClass().getCanonicalName());
journal.write("\n");
String arguments = Arrays
.stream(proceedingJoinPoint.getArgs())
.map(o -> o.getClass().getCanonicalName() + " " + o.toString())
.reduce(new StringBuilder(), StringBuilder::append, StringBuilder::append)
.toString();
journal.write(arguments);
journal.write("\n");
long start = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
journal.write(result.toString());
journal.write("\n");
journal.write(String.valueOf(System.currentTimeMillis() - start));
journal.write("\n\n");
journal.flush();
return result;
}
}
샘플 클래스 :
package repository;
import java.io.Serializable;
public class Task implements Serializable
{
private static final long serialVersionUID = 1L;
enum Status {NEW, IN_PROGRESS, FINISHED};
private Integer id;
private String description;
private Employee assignee;
private Employee reporter;
private Status status;
public Task(final Integer id, String description, final Employee assignee, final Employee reporter) {
this.id = id;
this.assignee = assignee;
this.reporter = reporter;
this.description = description;
this.status = Status.NEW;
}
public Employee getAssignee() {
return assignee;
}
public void setAssignee(Employee assignee) {
this.assignee = assignee;
}
...
}
나는 근래에 IntelliJ IDEA Ultimate 2017.2에서는 모든 메소드 (getter 및 setter)가 필자의 포인트 - 포인트라고 올바르게 암시합니다. 그것은 또한 내 측면에서 조언 "로그"에 대한 여러 포인트 - 컷이 나에게 암시. 그러나 "모든"충고는 암시하지 않습니다. 내가 좋아하는 플러그인 (최신 버전)를 설치 한
: - AspectJ를 지원 은 - 스프링 AOP AspectJ를
@Gradle을이 프로젝트에 대해 자동으로 생성 라이브러리 그래서 그것을 중복되지 않은 종속성/- AspectJ를가 위버.
빌드 : AspectJ 직조가 가능합니다.
설정> 빌드, 실행은 배포> 컴파일러> 자바 컴파일러 :
사용 컴파일러 : AJC에 AJC
경로 컴파일 : /home/me/.gradle/caches/modules-2/files- 2.1/org.aspectj/aspectjtools/1.8.10/5c5957ee4615bde33b54ce965f5b85b8827b97d5/aspectjtools-1.8.10.jar
명령 줄 매개 변수 : 빈 디버그 정보를 생성
: 체크 javac의에위임은 :
이 주석 처리 옵션을 사용 chcecked : 프로젝트 빌드 및 문제없이 컴파일
를 확인했습니다. 어떤 측면도 없었던 것처럼 실행됩니다. 특성은 아무 것도 출력되지 않고 임시 파일이 만들어지지 않으며, 모든 메서드가 잘 실행됩니다 (내 "모든"조언이 주위의 조인트 포인트를 처리하지 않았지만).
조언의 첫 번째 줄에 중단 점을 만들고 디버거와 함께 프로젝트를 실행할 때 아무 것도 잡히지 않습니다.
무엇이 누락 되었습니까?