Skip to content

io microsphere spring context event LoggingBeanListener

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

LoggingBeanListener

Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.context.event | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/context/event/LoggingBeanListener.java

Overview

A BeanListener implementation that provides comprehensive logging for various bean lifecycle events.

This class logs events at different stages of a bean's lifecycle, including bean definition readiness, instantiation, property value setup, initialization, and destruction. All log messages are generated using the io.microsphere.logging.Logger interface, and can be controlled based on the active logging level.

Logged Events

- `#onBeanDefinitionReady(String, RootBeanDefinition)` - When a bean definition is ready.
- `#onBeforeBeanInstantiate(String, RootBeanDefinition)` - Before a bean is instantiated.
- `#onBeforeBeanInstantiate(String, RootBeanDefinition, Constructor, Object[])` - Before a bean is
instantiated using a specific constructor.
- `#onBeforeBeanInstantiate(String, RootBeanDefinition, Object, Method, Object[])` - Before a bean is
instantiated using a factory method.
- `#onAfterBeanInstantiated(String, RootBeanDefinition, Object)` - After a bean has been instantiated.
- `#onBeanPropertyValuesReady(String, Object, PropertyValues)` - When property values are ready for a bean.
- `#onBeforeBeanInitialize(String, Object)` - Before a bean is initialized.
- `#onAfterBeanInitialized(String, Object)` - After a bean has been initialized.
- `#onBeanReady(String, Object)` - When a bean is fully ready for use.
- `#onBeforeBeanDestroy(String, Object)` - Before a bean is destroyed.
- `#onAfterBeanDestroy(String, Object)` - After a bean has been destroyed.

Logging Examples

Basic Logging

When a bean is instantiated:

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition...

Constructor-based Instantiation

When a bean is instantiated using a specific constructor:

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition... , constructor : public ExampleBean(String arg) , args : [testArg]

Factory Method-based Instantiation

When a bean is created using a factory method:

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition... , factoryBean : com.example.FactoryBean@12345 , factoryMethod : createBean , args : [testArg]

Property Injection

When property values are set on a bean:

onBeanPropertyValuesReady - bean name : exampleBean , instance : com.example.ExampleBean@67890 , PropertyValues : {name=testValue}

Bean Initialization

Before and after bean initialization:

onBeforeBeanInitialize - bean name : exampleBean , instance : com.example.ExampleBean@67890
onAfterBeanInitialized - bean name : exampleBean , instance : com.example.ExampleBean@67890

Bean Destruction

Before and after bean destruction:

onBeforeBeanDestroy - bean name : exampleBean , instance : com.example.ExampleBean@67890
onAfterBeanDestroy - bean name : exampleBean , instance : com.example.ExampleBean@67890

These logs help in debugging and understanding the Spring bean lifecycle, especially useful in complex applications where bean creation and management need to be closely monitored.

Declaration

public class LoggingBeanListener implements BeanListener

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

Example 1

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition...

Example 2

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition... , constructor : public ExampleBean(String arg) , args : [testArg]

Example 3

onBeforeBeanInstantiate - bean name : exampleBean , definition : RootBeanDefinition... , factoryBean : com.example.FactoryBean@12345 , factoryMethod : createBean , args : [testArg]

Example 4

onBeanPropertyValuesReady - bean name : exampleBean , instance : com.example.ExampleBean@67890 , PropertyValues : {name=testValue}

Example 5

onBeforeBeanInitialize - bean name : exampleBean , instance : com.example.ExampleBean@67890
onAfterBeanInitialized - bean name : exampleBean , instance : com.example.ExampleBean@67890

Example 6

onBeforeBeanDestroy - bean name : exampleBean , instance : com.example.ExampleBean@67890
onAfterBeanDestroy - bean name : exampleBean , instance : com.example.ExampleBean@67890

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.context.event.LoggingBeanListener;

API Reference

Public Methods

Method Description
supports
onBeanDefinitionReady
onBeforeBeanInstantiate
onBeforeBeanInstantiate
onBeforeBeanInstantiate
onAfterBeanInstantiated
onBeanPropertyValuesReady
onBeforeBeanInitialize
onAfterBeanInitialized
onBeanReady
onBeforeBeanDestroy
onAfterBeanDestroy

See Also

  • EventPublishingBeanInitializer
  • EventPublishingBeanBeforeProcessor
  • EventPublishingBeanAfterProcessor
  • BeanListeners
  • BeanListener
  • BeanListenerAdapter

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