Closed arccode closed 4 years ago
调用链: ServiceA -> ServiceB -> ServiceC
@AopLog(type = "ServiceA", stackTraceOnErr = true) @Service public class ServiceA implements IServiceA {
@Resource private IServiceB serviceB;
public void execute() {
LogData.step("A-Begin"); ... serviceB.execute(); LogData.step("A-End");
} }
@AopLog(type = "ServiceB", stackTraceOnErr = true) @Service public class ServiceB implements IServiceB {
@Resource private IServiceC serviceC;
LogData.step("B-Begin"); ... serviceC.execute(); LogData.step("B-End");
@AopLog(type = "ServiceC", stackTraceOnErr = true) @Service public class ServiceC implements IServiceC {
LogData.step("C-Begin"); ... LogData.step("C-End"); }
结果:
日志 B-End、C-End丢失
只需要再A上面加AopLog即可。不需要每个类上都打,还是说的你场景是所有类的所有参数都需要拦截?
只要LogData.step在被@AopLog拦截的整体方法链路内(包括此方法调用的其他外部方法内)被调用,都是有效的。再者这样每个方法都做切面拦截,对效率是有所影响的。
调用链: ServiceA -> ServiceB -> ServiceC
@AopLog(type = "ServiceA", stackTraceOnErr = true) @Service public class ServiceA implements IServiceA {
@Resource private IServiceB serviceB;
public void execute() {
LogData.step("A-Begin"); ... serviceB.execute(); LogData.step("A-End");
} }
@AopLog(type = "ServiceB", stackTraceOnErr = true) @Service public class ServiceB implements IServiceB {
@Resource private IServiceC serviceC;
public void execute() {
LogData.step("B-Begin"); ... serviceC.execute(); LogData.step("B-End");
} }
@AopLog(type = "ServiceC", stackTraceOnErr = true) @Service public class ServiceC implements IServiceC {
LogData.step("C-Begin"); ... LogData.step("C-End"); }
结果:
日志 B-End、C-End丢失