所以基本上我的情况是:
我有一个相当大的项目在工作,我必须用蚂蚁来构建它。我们正在使用Lombok,所以我不能只使用ajc对其进行编译(因为我发现ajc无法使用注释处理,因此我需要先使用Java对其进行编译,然后将其以.class二进制的形式进行编织)。
在Intellij代码中编译就可以了,但是当我运行ant build时,我遇到了一个pjp错误:[aspectj:iajc] [error 3]: error at C:\DBO-Server\java\DBO-Server\jk-out!by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.class::0 use of ProceedingJoinPoint is allowed only on around advice (arg 1 in (before(extraFlags: 2): (@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit) && persingleton(by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger))->void by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger.watchBefore(org.aspectj.lang.JoinPoint, by.bps.sbolbusiness.loggers.annotations.EnableAudit)))
据我所知,我的问题是
ProceedingJoinPoint仅适用于周围建议
在
watchBefore(org.aspectj.lang.JoinPoint,by.bps.sbolbusiness.loggers.annotations.EnableAudit))
要注意的是,如您所见,此方法中没有 ProceedingJoinPoint !只有简单的 JoinPoint
@Aspect
@Slf4j
public class BaseServiceLogger {
....
@Pointcut("@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit)&&@annotation(marker)")
public void logService(EnableAudit marker) {}
@Before(value = "logService(marker)", argNames = "jp,marker")
public void watchBefore(JoinPoint jp, EnableAudit marker) {
startMessage(jp, marker);
}
....
}
这是我的build.xml
<?xml version="1.0"?>
<project xmlns:aspectj="antlib:org.aspectj" name="SBOL-Business" default="build">
<property name="src" location="jk-src"/>
<property name="out" location="jk-out"/>
<property name="a-out" location="jk-a"/>
<property name="libs" location="..\..\Shared\lib"/>
<property name="webLibs" location="C:\Program Files\Apache Tomcat\current\lib"/>
<property name="daoSrc" location="..\..\Shared\Dao"/>
<property name="constantsSrc" location="..\..\Shared\Constants"/>
<property environment="env"/>
<target name="assemble">
<mkdir dir="${src}"/>
<copy todir="${src}">
<fileset dir="src"/>
</copy>
<copy todir="${src}">
<fileset dir="${daoSrc}"/>
</copy>
<copy todir="${src}">
<fileset dir="${constantsSrc}"/>
</copy>
</target>
<target name="compile.javac" depends="assemble">
<mkdir dir="${out}"/>
<javac srcdir="${src}" destdir="${out}" includeantruntime="false" encoding="UTF-8" debug="true">
<classpath>
<fileset dir="${libs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${webLibs}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="compile.aspectj" depends="compile.javac">
<mkdir dir="${a-out}"/>
<aspectj:iajc source="1.8" destDir="jk-a" XnoInline="false">
<inpath>
<pathelement location="${out}" />
</inpath>
<classpath>
<fileset dir="${libs}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${webLibs}">
<include name="**/*.jar" />
</fileset>
</classpath>
</aspectj:iajc>
</target>
<target name="clean" depends="compile.aspectj">
<delete dir="${src}"/>
<delete dir="${out}"/>
<delete dir="${a-out}"/>
</target>
<target name="build" depends="clean"/>
这里有带注释的 @EnableAudit 示例:
@EnableAudit(additionaInfo = true, serviceName = "Request AccountsQueryRq")
public GetOrgUserAccountsOverviewRs process(String loginName, Long customerId) {
//Method code
}
这是方面.java类:
package by.bps.sbolbusiness.loggers.pointcut;
import by.bps.sbolbusiness.loggers.annotations.EnableAudit;
import by.bps.sbolbusiness.loggers.utils.LogLevel;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.util.StopWatch;
@Aspect
@Slf4j
public class BaseServiceLogger {
private StopWatch sw;
//Some variables
@Pointcut("@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit)&&@annotation(marker)")
public void logService(EnableAudit marker) {}
@Before(value = "logService(marker)", argNames = "jp,marker")
public void watchBefore(JoinPoint jp, EnableAudit marker) {
startMessage(jp, marker);
}
@AfterReturning(value = "logService(marker)", argNames = "marker")
public void watchAfter(EnableAudit marker) {
finishMessage(marker);
}
@AfterThrowing(value = "logService(marker)", argNames = "marker")
public void watchAfterException(EnableAudit marker) {
throwingMessage(marker);
}
private void startMessage(JoinPoint jp, EnableAudit marker) {
//Long code
}
private void finishMessage(EnableAudit marker) {
//More long code here
}
private void throwingMessage(EnableAudit marker) {
//And more code
}
private void details(JoinPoint jp, StringBuilder sb) {
//Some other code here
}
}
考虑到代码可以在IDE中编译并运行,我认为我的构建脚本有问题。有人可以帮我吗?也许我需要传递一些参数给iajc或其他东西?在这一点上,我尝试了一切我都无法成功的事情
编辑: ant输出日志:
Buildfile: C:\DBO-Server\java\DBO-Server\build.xml
assemble:
[copy] Copying 1 file to C:\DBO-Server\java\DBO-Server\jk-src
compile.javac:
[javac] Compiling 4 source files to C:\DBO-Server\java\DBO-Server\jk-out
compile.aspectj:
[aspectj:iajc] MessageHolder: (2908 info) (96 error)
[aspectj:iajc] [error 0]: error at by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.java::0 the parameter marker is not bound in [all branches of] pointcut
[aspectj:iajc] [error 1]: error at by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.java::0 the parameter marker is not bound in [all branches of] pointcut
[aspectj:iajc] [error 2]: error at by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.java::0 the parameter marker is not bound in [all branches of] pointcut
[aspectj:iajc] [error 3]: error at C:\DBO-Server\java\DBO-Server\jk-out!by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.class::0 use of ProceedingJoinPoint is allowed only on around advice (arg 1 in (before(extraFlags: 2): (@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit) && persingleton(by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger))->void by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger.watchBefore(org.aspectj.lang.JoinPoint, by.bps.sbolbusiness.loggers.annotations.EnableAudit)))
[aspectj:iajc] [error 4]: error at C:\DBO-Server\java\DBO-Server\jk-out!by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.class::0 use of ProceedingJoinPoint is allowed only on around advice (arg 0 in (afterReturning: (@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit) && persingleton(by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger))->void by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger.watchAfter(by.bps.sbolbusiness.loggers.annotations.EnableAudit)))
... about 70+ identical lines ...
[aspectj:iajc] [error 94]: error at C:\DBO-Server\java\DBO-Server\jk-out!by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.class::0 use of ProceedingJoinPoint is allowed only on around advice (arg 0 in (afterReturning: (@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit) && persingleton(by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger))->void by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger.watchAfter(by.bps.sbolbusiness.loggers.annotations.EnableAudit)))
[aspectj:iajc] [error 95]: error at C:\DBO-Server\java\DBO-Server\jk-out!by\bps\sbolbusiness\loggers\pointcut\BaseServiceLogger.class::0 use of ProceedingJoinPoint is allowed only on around advice (arg 0 in (afterThrowing: (@annotation(by.bps.sbolbusiness.loggers.annotations.EnableAudit) && persingleton(by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger))->void by.bps.sbolbusiness.loggers.pointcut.BaseServiceLogger.watchAfterException(by.bps.sbolbusiness.loggers.annotations.EnableAudit)))