Class SpringApplicationContextFacade
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware
ApplicationEventPublisher to components as Views or Perspectives which are directly
managed by Eclipse and consequently cannot be initialised by Spring-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidaddApplicationContextAsParent(org.springframework.context.support.AbstractApplicationContext child) Associates anApplicationContextparent to theApplicationContextdefined in this instancestatic final booleanaddApplicationListener(org.springframework.context.ApplicationListener<?> listener) Attached a listener to the application context in order to be notified when new events occur.static final voidaddDisposableApplicationListener(Object object, org.springframework.context.ApplicationListener<?> listener) voidClose the running spring framework.static <T> TReturn the bean instance that uniquely matches the given object type, if any.static <T> TReturn the bean instance that uniquely matches the given object type, if any.static <T> TReturn an instance, which may be shared or independent, of the specified bean.static ObjectReturn an instance, which may be shared or independent, of the specified bean.static <T> Optional<T> getOptionalBean(Class<T> bean) static voidThere are cases where closing Spring is not enough to make an instance unavailable.static final voidpublishEvent(org.springframework.context.ApplicationEvent event) static final voidremoveApplicationListener(org.springframework.context.ApplicationListener<?> listener) Removes a listener from the ApplicationContext.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationPublisher)
-
Constructor Details
-
SpringApplicationContextFacade
public SpringApplicationContextFacade()
-
-
Method Details
-
preDestroy
@PreDestroy public static void preDestroy()There are cases where closing Spring is not enough to make an instance unavailable. This class contains as static some properties which are still available after spring, not the JVM, is destroyed. This method guarantee to clean up this component when spring is destroyed -
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationPublisher) - Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
closeSpringFramework
public void closeSpringFramework()Close the running spring framework.Use carefully!
-
publishEvent
public static final void publishEvent(org.springframework.context.ApplicationEvent event) -
addApplicationListener
public static final boolean addApplicationListener(org.springframework.context.ApplicationListener<?> listener) Attached a listener to the application context in order to be notified when new events occur.- Parameters:
listener-- Returns:
trueif succeed,falseifSpringApplicationContextFacadeno access to SpringConfigurableApplicationContext
-
removeApplicationListener
public static final void removeApplicationListener(org.springframework.context.ApplicationListener<?> listener) Removes a listener from the ApplicationContext.- Parameters:
listener- the listener to remove. Ifnulldoes nothing
-
getBean
Return the bean instance that uniquely matches the given object type, if any.- Parameters:
requiredType- type the bean must match; can be an interface or superclass.nullis disallowed.This method goes into
ListableBeanFactoryby-type lookup territory but may also be translated into a conventional by-name lookup based on the name of the given type. For more extensive retrieval operations across sets of beans, useListableBeanFactoryand/orBeanFactoryUtils.- Returns:
- an instance of the single bean matching the required type
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was found
-
getBean
Return the bean instance that uniquely matches the given object type, if any.- Parameters:
name- the name of the bean to retrieverequiredType- type the bean must match; can be an interface or superclass.nullis disallowed.This method goes into
ListableBeanFactoryby-type lookup territory but may also be translated into a conventional by-name lookup based on the name of the given type. For more extensive retrieval operations across sets of beans, useListableBeanFactoryand/orBeanFactoryUtils.- Returns:
- an instance of the single bean matching the required type
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was found
-
getBean
Return an instance, which may be shared or independent, of the specified bean.- Type Parameters:
T-- Parameters:
name- the name of the bean to retrieverequiredType- type the bean must match. Can be an interface or superclass of the actual class, ornullfor any match. For example, if the value isObject.class, this method will succeed whatever the class of the returned instance.fromParent- iftruethe bean is requested from the parentApplicationContext, otherwise from the one in this instance.- Returns:
- an instance of the single bean matching the required type
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was found
-
getBean
Return an instance, which may be shared or independent, of the specified bean.Allows for specifying explicit constructor arguments / factory method arguments, overriding the specified default arguments (if any) in the bean definition.
- Parameters:
name- the name of the bean to retrieveargs- arguments to use if creating a prototype using explicit arguments to a static factory method. It is invalid to use a non-null args value in any other case.- Returns:
- an instance of the bean
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if there is no such bean definitionorg.springframework.beans.factory.BeanDefinitionStoreException- if arguments have been given but the affected bean isn't a prototype
-
getOptionalBean
-
addDisposableApplicationListener
public static final void addDisposableApplicationListener(Object object, org.springframework.context.ApplicationListener<?> listener) - Parameters:
object- the element publishing the dispose event which causeslistenerto be removedlistener- the application lister to
-
addApplicationContextAsParent
public static final void addApplicationContextAsParent(org.springframework.context.support.AbstractApplicationContext child) Associates anApplicationContextparent to theApplicationContextdefined in this instance- Parameters:
child-
-