我有一个类似下面的 Java 类:
public class Foo{
public void doSomething(){
StageA a = new StageA();
StageB b = new StageB();
StageC c = new StageC();
a.execute();
b.execute();
c.execute();
}
}
现在,假设我不能真正编辑这个类本身,我仍然可以使用 spring AOP 来应用日志记录 around
execute
方法? (大概没有使用 aspect4j)
最佳答案
好吧,你可以记录方法,它需要时间(为了性能),但我不认为你能够记录方法正在做什么。
来自 Spring Docs :
Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.
如果您在方法内部使用 log4j 记录器,则可以通过配置 log4j 来记录方法正在执行的操作。
(presumably without using aspect4j)
--> Spring内部使用了aspectJ
检查 here供引用和举例
关于java - Spring:spring 可以访问在 spring 管理的 bean 中私有(private)创建的对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951368/