|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.qos.logback.ext.spring.ApplicationContextHolder
public class ApplicationContextHolder
A special bean which may be defined in the Spring ApplicationContext
to make the context available statically
to objects which, for whatever reason, cannot be wired up in Spring (for example, logging appenders which must be
defined in XML or properties files used to initialize the logging system).
<bean class="ch.qos.logback.ext.spring.ApplicationContextHolder"/>Note that no ID is necessary because this holder should always be used via its static accessors, rather than being injected. Any Spring bean which wishes to access the
ApplicationContext
should not rely on this holder; it
should simply implement ApplicationContextAware
.
WARNING: This object uses static memory to retain the ApplicationContext. This means this bean (and the
related configuration strategy) is only usable when no other Logback-enabled Spring applications exist in the same
JVM.
Constructor Summary | |
---|---|
ApplicationContextHolder()
|
Method Summary | |
---|---|
static org.springframework.context.ApplicationContext |
getApplicationContext()
Retrieves the ApplicationContext set when Spring created and initialized the holder bean. |
static boolean |
hasApplicationContext()
Ensures that the ApplicationContext has been set and that it has been refreshed. |
static boolean |
isRefreshed()
Returns a flag indicating whether the ApplicationContext has been refreshed. |
void |
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
|
void |
setApplicationContext(org.springframework.context.ApplicationContext context)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ApplicationContextHolder()
Method Detail |
---|
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
onApplicationEvent
in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public static boolean hasApplicationContext()
ApplicationContext
has been set and that it has been refreshed. The refresh
event is sent when the context has completely finished starting up, meaning all beans have been created and
initialized successfully.
This method has a loosely defined relationship with getApplicationContext()
. When this method returns
true
, calling getApplicationContext()
is guaranteed to return a non-null
context which
has been completely initialized. When this method returns false
, getApplicationContext()
may
return null
, or it may return a non-null
context which is not yet completely initialized.
true
if the context has been set and refreshed; otherwise, false
public static org.springframework.context.ApplicationContext getApplicationContext()
ApplicationContext
set when Spring created and initialized the holder bean. If the
holder has not been created (see the class documentation for details on how to wire up the holder), or if
the holder has not been initialized, this accessor may return null
.
As a general usage pattern, callers should wrap this method in a check for hasApplicationContext()
.
That ensures both that the context is set and also that it has fully initialized. Using a context which has
not been fully initialized can result in unexpected initialization behaviors for some beans. The most common
example of this behavior is receiving unproxied references to some beans, such as beans which were supposed
to have transactional semantics applied by AOP. By waiting for the context refresh event, the likelihood of
encountering such behavior is greatly reduced.
null
if the holder bean has not been initializedpublic void setApplicationContext(org.springframework.context.ApplicationContext context) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public static boolean isRefreshed()
ApplicationContext
has been refreshed. Theoretically, it is
possible for this method to return true
when hasApplicationContext()
returns false
,
but in practice that is very unlikely since the bean for the holder should have been created and initialized
before the refresh event was raised.
true
if the context refresh event has been received; otherwise, false
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |