Package org.genesys.blocks.util
Class CurrentApplicationContext
java.lang.Object
org.genesys.blocks.util.CurrentApplicationContext
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
public class CurrentApplicationContext
extends Object
implements org.springframework.context.ApplicationContextAware
Based on this Stackoveflow
comment.
The bean exposes the current Spring application context to static methods.
Register it as
@Bean
public CurrentApplicationContext currentAppContext() {
return new CurrentApplicationContext();
}
Once registered, static methods can obtain bean references:
static {
SomeService myService = CurrentApplicationContext.getContext().getBean(...);
}
public static void foo() {
SomeBean bean = CurrentApplicationComntext.getContext().getBean(...);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.context.ApplicationContextNote that this is a static method which expose ApplicationContext.voidsetApplicationContext(org.springframework.context.ApplicationContext context)
-
Constructor Details
-
CurrentApplicationContext
public CurrentApplicationContext()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext context) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getContext
public static org.springframework.context.ApplicationContext getContext()Note that this is a static method which expose ApplicationContext.- Returns:
- the instance of the current Spring
ApplicationContext
-