前面介绍了InstantiationAwareBeanPostProcessor后置处理器的postProcessBeforeInstantiation和postProcessAfterInstantiation两个方法的用法和使用场景等。在InstantiationAwareBeanPostProcessor中还有两个方法,分别是postProcessProperties和postProcessPropertyValues,从这两个方法的名称上来看,它们完成的功能似乎很相近,下面来看具体的方法。
一、概述在InstantiationAwarePostProcessor接口中的两个方法如下,
二、详述在InstantiationAwareBeanPostProcessor接口中找到两个方法的定义如下,
/** * Post-process the given property values before the factory applies them * to the given bean, without any need for property descriptors. * <p>Implementations should return {@code null} (the default) if they provide a custom * {@link #postProcessPropertyValues} implementation, and {@code pvs} otherwise. * In a future version of this interface (with {@link #postProcessPropertyValues} removed), * the default implementation will return the given {@code pvs} as-is directly. * @param pvs the property values that the factory is about to apply (never {@code null}) * @param bean the bean instance created, but whose properties have not yet been set * @param beanName the name of the bean * @return the actual property values to apply to the given bean (can be the passed-in * PropertyValues instance), or {@code null} which proceeds with the existing properties * but specifically continues with a call to {@link #postProcessPropertyValues} * (requiring initialized {@code PropertyDescriptor}s for the current bean class) * @throws org.springframework.beans.BeansException in case of errors * @since 5.1 * @see #postProcessPropertyValues */ @Nullable default PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException { return null; }