Skip to content

io microsphere spring beans factory config GenericBeanPostProcessorAdapter

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

GenericBeanPostProcessorAdapter

Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.beans.factory.config | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/beans/factory/config/GenericBeanPostProcessorAdapter.java

Overview

Generic adapter implementation of the BeanPostProcessor interface, providing type-safe processing for beans of a specific type. This class simplifies the development of typed BeanPostProcessor implementations by allowing subclasses to handle only the bean types they are interested in.

Subclasses can override either the pre / post initialization hook methods (#processBeforeInitialization(Object, String) and #processAfterInitialization(Object, String)) if they wish to perform processing without returning a modified bean instance, or the more advanced #doPostProcessBeforeInitialization(Object, String) and #doPostProcessAfterInitialization(Object, String) methods if they need to return a modified bean instance.

Example Usage

`public class MyBeanPostProcessor extends GenericBeanPostProcessorAdapter {
    protected void processBeforeInitialization(MyBean bean, String beanName) {
        // Custom logic before bean initialization
    `

    protected void processAfterInitialization(MyBean bean, String beanName) {
        // Custom logic after bean initialization
    }
}
}

Declaration

public abstract class GenericBeanPostProcessorAdapter<T> implements BeanPostProcessor

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.27-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

public class MyBeanPostProcessor extends GenericBeanPostProcessorAdapter<MyBean> {
    protected void processBeforeInitialization(MyBean bean, String beanName) {
        // Custom logic before bean initialization
    }

    protected void processAfterInitialization(MyBean bean, String beanName) {
        // Custom logic after bean initialization
    }
}

Method Examples

postProcessBeforeInitialization

GenericBeanPostProcessorAdapter<Bean> processor = new GenericBeanPostProcessorAdapter<Bean>() {
  };
  assertEquals(Bean.class, processor.getBeanType());
TestBean testBean = new TestBean();
  GenericBeanPostProcessorAdapter<Bean> processor = new GenericBeanPostProcessorAdapter<Bean>() {
      protected void processBeforeInitialization(Bean bean, String beanName) {
          // custom pre-initialization logic
      }
  };
  // matching type: delegates to doPostProcessBeforeInitialization
  assertEquals(testBean, processor.postProcessBeforeInitialization(testBean, "testBean"));
  // non-matching type: returns bean unchanged
  String other = "test";
  assertEquals("test", processor.postProcessBeforeInitialization(other, ""));

postProcessAfterInitialization

TestBean testBean = new TestBean();
  GenericBeanPostProcessorAdapter<Bean> processor = new GenericBeanPostProcessorAdapter<Bean>() {
      protected void processAfterInitialization(Bean bean, String beanName) {
          // custom post-initialization logic
      }
  };
  // matching type: delegates to doPostProcessAfterInitialization
  assertEquals(testBean, processor.postProcessAfterInitialization(testBean, "testBean"));
  // non-matching type: returns bean unchanged
  String other = "test";
  assertEquals("test", processor.postProcessAfterInitialization(other, ""));

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-context</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.beans.factory.config.GenericBeanPostProcessorAdapter;

API Reference

Public Methods

Method Description
postProcessBeforeInitialization Constructs a new GenericBeanPostProcessorAdapter, resolving the generic bean type
postProcessAfterInitialization Applies post-initialization post-processing to the given bean if it matches the resolved
getBeanType Bean Type

Method Details

postProcessBeforeInitialization

public final Object postProcessBeforeInitialization(Object bean, String beanName)

Constructs a new GenericBeanPostProcessorAdapter, resolving the generic bean type T from the subclass declaration. The resolved type is used to filter which beans this post-processor will handle.

Example Usage

`GenericBeanPostProcessorAdapter processor = new GenericBeanPostProcessorAdapter() {
  `;
  assertEquals(Bean.class, processor.getBeanType());
}

/ public GenericBeanPostProcessorAdapter() { this.beanType = (Class) resolveTypeArgument(getClass(), GenericBeanPostProcessorAdapter.class); }

/** Applies pre-initialization post-processing to the given bean if it matches the resolved bean type T. If the bean's type is assignable to T, delegates to #doPostProcessBeforeInitialization(Object, String); otherwise, returns the bean unchanged.

Example Usage

`TestBean testBean = new TestBean();
  GenericBeanPostProcessorAdapter processor = new GenericBeanPostProcessorAdapter() {
      protected void processBeforeInitialization(Bean bean, String beanName) {
          // custom pre-initialization logic
      `
  };
  // matching type: delegates to doPostProcessBeforeInitialization
  assertEquals(testBean, processor.postProcessBeforeInitialization(testBean, "testBean"));
  // non-matching type: returns bean unchanged
  String other = "test";
  assertEquals("test", processor.postProcessBeforeInitialization(other, ""));
}

postProcessAfterInitialization

public final Object postProcessAfterInitialization(Object bean, String beanName)

Applies post-initialization post-processing to the given bean if it matches the resolved bean type T. If the bean's type is assignable to T, delegates to #doPostProcessAfterInitialization(Object, String); otherwise, returns the bean unchanged.

Example Usage

`TestBean testBean = new TestBean();
  GenericBeanPostProcessorAdapter processor = new GenericBeanPostProcessorAdapter() {
      protected void processAfterInitialization(Bean bean, String beanName) {
          // custom post-initialization logic
      `
  };
  // matching type: delegates to doPostProcessAfterInitialization
  assertEquals(testBean, processor.postProcessAfterInitialization(testBean, "testBean"));
  // non-matching type: returns bean unchanged
  String other = "test";
  assertEquals("test", processor.postProcessAfterInitialization(other, ""));
}

See Also

  • BeanPostProcessor

This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally