java - BeanFactoryPostProcessor修改实际的bean定义而不是实例?

标签 java spring

这里简单介绍一下 BeanFactoryPostProcessor 的作用

A BeanFactoryPostProcessor lets you modify the actual bean definition instead of the instance as it's created.Spring IoC container will allow BeanFactoryPostProcessors to read the configuration metadata and potentially change it before the container has actually instantiated any bean. PropertyPlaceholderConfigurer is the example of BeanFactoryPostProcessors to externalize some property values into another separate file in Java Properties format

我从上面了解到的是 BeanFactoryPostProcessor 在应用程序上下文开始时修改 bean 定义(即在应用程序加载时)。 但我不知道它是否会物理地更改文件或内存中的类定义。

我在我的项目中使用PropertyPlaceholderConfigurer。为了验证这一点,应用程序启动后,我进入类路径并在反编译器中打开类文件 属性 {test.property} 是否被替换为实际值。它不是。那么spring会修改内存中的类定义吗?

最佳答案

BeanFactoryPostProcessor 不会更改物理类定义。在大多数生产应用程序中,运行应用程序的用户甚至无权“写入”文件。所有修改都会在类加载后发生。因此,当您需要一个bean实例时,Spring将加载bean定义(但不会实例化“任何”实例),应用注册的bean工厂后处理器,然后创建一个实例(然后应用bean后处理器,即与 bean 工厂后处理器不同),然后只返回 bean。

关于java - BeanFactoryPostProcessor修改实际的bean定义而不是实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35668993/

相关文章:

java : converting hexadecimal number string to decimal

java - 如何判断我的应用程序是否是第一次运行?

java - 模拟Mongo Write Lock来衡量性能

找不到从 JSP/ Controller 路径加载的 Javascript

java - Oracle 存储过程 - Spring 集成 - OUT 类型对象

java - 一种递归求解邮票问题的算法

java - 根据类别拆分数组列表的最佳方法

java - centos 无法连接mysql

java - Spring Security + Google App Engine + UserService : What is the correct way to logout?

java - Hibernate 加入两个表并获取所有记录?