public class SpringContextBootstrappingInitializer extends Object implements org.apache.geode.cache.Declarable, ApplicationListener<ApplicationContextEvent>
SpringContextBootstrappingInitializer
class is a GemFire configuration initializer used to bootstrap
a Spring ApplicationContext
inside a GemFire Server JVM-based process. This enables a GemFire Server
resource to be mostly configured with Spring Data GemFire's configuration meta-data. The GemFire Cache
itself is the only resource that cannot be configured and initialized in a Spring context since the initializer
is not invoked until after GemFire creates and initializes the GemFire Cache
for use.ApplicationContext
,
ApplicationListener
,
ConfigurableApplicationContext
,
AnnotationConfigApplicationContext
,
ApplicationContextEvent
,
ApplicationEventMulticaster
,
ClassPathXmlApplicationContext
,
DefaultResourceLoader
,
Cache
,
Declarable
Modifier and Type | Field and Description |
---|---|
static String |
BASE_PACKAGES_PARAMETER |
protected static String |
CHARS_TO_DELETE |
protected static String |
COMMA_DELIMITER |
static String |
CONTEXT_CONFIG_LOCATIONS_PARAMETER |
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
SpringContextBootstrappingInitializer() |
Modifier and Type | Method and Description |
---|---|
protected ConfigurableApplicationContext |
createApplicationContext(String[] basePackages,
String[] configLocations)
Creates (constructs and configures) an instance of the ConfigurableApplicationContext based on either the
specified base packages containing @Configuration, @Component or JSR 330 annotated classes to scan, or the
specified locations of context configuration meta-data files.
|
static ConfigurableApplicationContext |
getApplicationContext()
Gets a reference to the Spring ApplicationContext constructed, configured and initialized inside the GemFire
Server-based JVM process.
|
void |
init(org.apache.geode.cache.Cache cache,
Properties parameters)
Initializes a Spring
ApplicationContext with the given parameters specified with an Apache Geode
or Pivotal GemFire <initializer> block in cache.xml. |
void |
init(Properties parameters) |
protected ConfigurableApplicationContext |
initApplicationContext(ConfigurableApplicationContext applicationContext)
Initializes the given ApplicationContext by registering this SpringContextBootstrappingInitializer as an
ApplicationListener and registering a runtime shutdown hook.
|
protected org.slf4j.Logger |
initLogger()
Initialization method for the logger used to log important messages from this initializer.
|
protected static void |
notifyOnExistingContextRefreshedEvent(ApplicationListener<ContextRefreshedEvent> listener)
Notifies any Spring ApplicationListeners of a current and existing ContextRefreshedEvent if the
ApplicationContext had been previously created, initialized and refreshed before any ApplicationListeners
interested in ContextRefreshedEvents were registered so that application components (such as the
GemFire CacheLoaders extending LazyWiringDeclarableSupport objects) registered late, requiring configuration
(auto-wiring), also get notified and wired accordingly.
|
void |
onApplicationEvent(ApplicationContextEvent event)
Gets notified when the Spring ApplicationContext gets created and refreshed by GemFire, once the
<initializer> block is processed and the SpringContextBootstrappingInitializer Declarable component
is initialized.
|
protected ConfigurableApplicationContext |
refreshApplicationContext(ConfigurableApplicationContext applicationContext)
Refreshes the given ApplicationContext making the context active.
|
static boolean |
register(Class<?> annotatedClass)
Registers the specified Spring annotated POJO class, which will be used to configure and initialize
the Spring ApplicationContext.
|
static <T extends ApplicationListener<ContextRefreshedEvent>> |
register(T listener)
Registers a Spring ApplicationListener to be notified when the Spring ApplicationContext is created by GemFire
when instantiating and initializing Declarables declared inside the <initializer> block inside GemFire's
cache.xml file.
|
static void |
setBeanClassLoader(ClassLoader beanClassLoader)
Sets the ClassLoader used by the Spring ApplicationContext, created by this GemFire Initializer, when creating
bean definition classes.
|
static boolean |
unregister(Class<?> annotatedClass)
Un-registers the specified Spring annotated POJO class used to configure and initialize
the Spring ApplicationContext.
|
static <T extends ApplicationListener<ContextRefreshedEvent>> |
unregister(T listener)
Un-registers the Spring ApplicationListener from this SpringContextBootstrappingInitializer in order to stop
receiving ApplicationEvents on Spring context refreshes.
|
public static final String BASE_PACKAGES_PARAMETER
public static final String CONTEXT_CONFIG_LOCATIONS_PARAMETER
protected static final String CHARS_TO_DELETE
protected static final String COMMA_DELIMITER
protected final org.slf4j.Logger logger
public SpringContextBootstrappingInitializer()
public static ConfigurableApplicationContext getApplicationContext()
ConfigurableApplicationContext
public static void setBeanClassLoader(ClassLoader beanClassLoader)
beanClassLoader
- the ClassLoader used by the Spring ApplicationContext to load bean definition classes.IllegalStateException
- if the Spring ApplicationContext has already been created
and initialized.ClassLoader
protected static void notifyOnExistingContextRefreshedEvent(ApplicationListener<ContextRefreshedEvent> listener)
listener
- a Spring ApplicationListener requiring notification of any ContextRefreshedEvents after the
ApplicationContext has already been created, initialized and/or refreshed.ApplicationListener.onApplicationEvent(org.springframework.context.ApplicationEvent)
,
ContextRefreshedEvent
public static <T extends ApplicationListener<ContextRefreshedEvent>> T register(T listener)
T
- the Class type of the Spring ApplicationListener.listener
- the ApplicationListener to register for ContextRefreshedEvents multi-casted by this
SpringContextBootstrappingInitializer.notifyOnExistingContextRefreshedEvent(org.springframework.context.ApplicationListener)
,
unregister(org.springframework.context.ApplicationListener)
,
ApplicationListener
,
ContextRefreshedEvent
,
#addApplicationListener(org.springframework.context.ApplicationListener)
public static boolean register(Class<?> annotatedClass)
annotatedClass
- the Spring annotated (@Configuration) POJO class to register.unregister(Class)
public static <T extends ApplicationListener<ContextRefreshedEvent>> T unregister(T listener)
T
- the Class type of the Spring ApplicationListener.listener
- the ApplicationListener to unregister from receiving ContextRefreshedEvents by this
SpringContextBootstrappingInitializer.register(org.springframework.context.ApplicationListener)
,
ApplicationListener
,
ContextRefreshedEvent
,
#removeApplicationListener(org.springframework.context.ApplicationListener)
public static boolean unregister(Class<?> annotatedClass)
annotatedClass
- the Spring annotated (@Configuration) POJO class to unregister.register(Class)
protected org.slf4j.Logger initLogger()
LogFactory.getLog(Class)
,
Log
protected ConfigurableApplicationContext createApplicationContext(String[] basePackages, String[] configLocations)
basePackages
- the base packages to scan for application @Components and @Configuration classes.configLocations
- a String array indicating the locations of the context configuration meta-data files
used to configure the ClassPathXmlApplicationContext instance.IllegalArgumentException
- if both the basePackages and configLocation parameter arguments
are null or empty.createApplicationContext(String[])
,
AnnotationConfigApplicationContext
,
AnnotationConfigApplicationContext.scan(String...)
,
ClassPathXmlApplicationContext
protected ConfigurableApplicationContext initApplicationContext(ConfigurableApplicationContext applicationContext)
applicationContext
- the ConfigurableApplicationContext to initialize.IllegalArgumentException
- if the ApplicationContext reference is null!ConfigurableApplicationContext
,
ConfigurableApplicationContext.addApplicationListener(org.springframework.context.ApplicationListener)
,
ConfigurableApplicationContext.registerShutdownHook()
protected ConfigurableApplicationContext refreshApplicationContext(ConfigurableApplicationContext applicationContext)
applicationContext
- the ConfigurableApplicationContext to refresh.IllegalArgumentException
- if the ApplicationContext reference is null!ConfigurableApplicationContext
,
ConfigurableApplicationContext.refresh()
public void init(Properties parameters)
init
in interface org.apache.geode.cache.Declarable
public void init(org.apache.geode.cache.Cache cache, Properties parameters)
ApplicationContext
with the given parameters specified with an Apache Geode
or Pivotal GemFire <initializer> block in cache.xml.parameters
- Properties
object containing the configuration parameters and settings defined in the
Apache Geode/Pivotal GemFire cache.xml <initializer> block for the declared
SpringContextBootstrappingInitializer
Apache Geode/Pivotal GemFire Declarable
object.cache
- reference to the peer Cache
.ApplicationContextException
- if the Spring ApplicationContext
could not be successfully constructed, configured and initialized.createApplicationContext(String[], String[])
,
initApplicationContext(org.springframework.context.ConfigurableApplicationContext)
,
refreshApplicationContext(org.springframework.context.ConfigurableApplicationContext)
,
Properties
public void onApplicationEvent(ApplicationContextEvent event)
onApplicationEvent
in interface ApplicationListener<ApplicationContextEvent>
event
- the ApplicationContextEvent signaling that the Spring ApplicationContext has been created
and refreshed by GemFire, or closed when the JVM process exits.ContextClosedEvent
,
ContextRefreshedEvent
,
#multicastEvent(org.springframework.context.ApplicationEvent)
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.