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 Constructor Description CurrentApplicationContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static org.springframework.context.ApplicationContextgetContext()Note that this is a static method which expose ApplicationContext.voidsetApplicationContext(org.springframework.context.ApplicationContext context)
-
-
-
Method Detail
-
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
-
-