Class ConfigurableApplicationContextInitializer

java.lang.Object
io.microsphere.spring.context.ConfigurableApplicationContextInitializer
All Implemented Interfaces:
EnvironmentEnabled, org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
Direct Known Subclasses:
AutoRegistrationBeanInitializer, EventPublishingBeanInitializer, ListenableAutowireCandidateResolverInitializer, ListenableConfigurableEnvironmentInitializer

public abstract class ConfigurableApplicationContextInitializer extends Object implements org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>, EnvironmentEnabled
An abstract base class for ApplicationContextInitializer implementations targeting ConfigurableApplicationContext. It provides built-in support for enabling or disabling the initializer via configuration properties, as well as automatic self-registration into the Spring context.

Example Usage


 public class MyCustomInitializer extends ConfigurableApplicationContextInitializer {

     @Override
     protected void initialize(ConfigurableApplicationContext context, ConfigurableEnvironment environment) {
         // Perform custom initialization logic here
     }
 }
 

By default, this initializer is enabled. To disable it, set the corresponding property to false:

 microsphere.spring.context-initializer.myCustomInitializer.enabled=false
 
Since:
1.0.0
Author:
Mercy
See Also:
  • ApplicationContextInitializer
  • ConfigurableApplicationContext
  • ConfigurableEnvironment
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final io.microsphere.logging.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    boolean
    Get the default value of enabled
    Get the property name of the enabled
    final void
    initialize(org.springframework.context.ConfigurableApplicationContext context)
     
    protected abstract void
    initialize(org.springframework.context.ConfigurableApplicationContext context, org.springframework.core.env.ConfigurableEnvironment environment)
    Initialize the ConfigurableApplicationContext.
    protected boolean
    isEnabled(org.springframework.context.ConfigurableApplicationContext context, org.springframework.core.env.ConfigurableEnvironment environment)
    Is enabled or not
    protected boolean
    isRegistered(org.springframework.context.ConfigurableApplicationContext context)
    Is registered or not
    protected void
    registerSelf(org.springframework.context.ConfigurableApplicationContext context)
    Register self to the ConfigurableApplicationContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.microsphere.spring.config.env.EnvironmentEnabled

    isEnabled
  • Field Details

    • logger

      protected final io.microsphere.logging.Logger logger
  • Constructor Details

    • ConfigurableApplicationContextInitializer

      public ConfigurableApplicationContextInitializer()
  • Method Details

    • initialize

      public final void initialize(org.springframework.context.ConfigurableApplicationContext context)
      Specified by:
      initialize in interface org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
    • initialize

      protected abstract void initialize(org.springframework.context.ConfigurableApplicationContext context, org.springframework.core.env.ConfigurableEnvironment environment)
      Initialize the ConfigurableApplicationContext.
      Parameters:
      context - the ConfigurableApplicationContext
      environment - the ConfigurableEnvironment
    • isEnabled

      protected boolean isEnabled(org.springframework.context.ConfigurableApplicationContext context, org.springframework.core.env.ConfigurableEnvironment environment)
      Is enabled or not
      Parameters:
      context - the ConfigurableApplicationContext
      environment - the ConfigurableEnvironment
      Returns:
      if enabled, return true, or false
      See Also:
    • getEnabledPropertyName

      public String getEnabledPropertyName()
      Get the property name of the enabled
      Specified by:
      getEnabledPropertyName in interface EnvironmentEnabled
      Returns:
      the property name of the enabled
      See Also:
    • getDefaultEnabled

      public boolean getDefaultEnabled()
      Get the default value of enabled
      Specified by:
      getDefaultEnabled in interface EnvironmentEnabled
      Returns:
      the default value of enabled
      See Also:
    • getBeanName

      protected String getBeanName()
      Returns:
      the bean name of this ConfigurableApplicationContextInitializer
      See Also:
    • isRegistered

      protected boolean isRegistered(org.springframework.context.ConfigurableApplicationContext context)
      Is registered or not
      Parameters:
      context - the ConfigurableApplicationContext
      Returns:
      if registered, return true, or false
    • registerSelf

      protected void registerSelf(org.springframework.context.ConfigurableApplicationContext context)
      Register self to the ConfigurableApplicationContext
      Parameters:
      context - the ConfigurableApplicationContext