java - Spring:spring 可以访问在 spring 管理的 bean 中私有(private)创建的对象吗?

标签 java spring spring-aop

我有一个类似下面的 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/

相关文章:

java - GAE Google App Engine 静态文件模式处理程序 Java 等效项?

java - 了解用于插入和更新语句的 jdbcTemplate

spring - 无法捕获 @AfterThrowing 建议中的 @Before 建议中引发的异常

java - 使用 Spring 或 AspectJ 将基于代码的样式转换为基于注释的 AOP

java - 根据建议的对象调用位置应用方面

java - 在 Selenium Grid 中注册 PhantomJS 节点时出错

java - 我如何加密和解密在 PHP 和 JAVA 之间使用 AES/GCM/

Java Spring applicationcontext 注册 BeanDefinition

java - 使用 Spring Integration 安排通过 FTP 进行远程文件下载并处理内存中的文件

java - Google App Engine 上的推送队列与拉取队列