Package org.dellroad.stuff.spring
Class Springleton
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.dellroad.stuff.spring.Springleton
- All Implemented Interfaces:
Aware
,ApplicationContextAware
Global singleton that provides access to the application context in which it is defined from anywhere.
Reminiscent of Spring's "evil singleton"
from days of yore.
This bean allows at most one instantiated instance per class loader, and that instance may be defined
in at most one ApplicationContext
. In particular, this means web containers hosting multiple
web applications must create separate class loaders per web application.
This class may be subclassed to add autowired properties, etc. If so, access the singleton in the same
way (i.e., via Springleton.getInstance()
) and then downcast as needed.
-
Field Summary
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
-
Constructor Summary
-
Method Summary
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Constructor Details
-
Springleton
public Springleton()Constructor.- Throws:
IllegalStateException
- if another instance has already been created in the same class loader
-
-
Method Details
-
getInstance
Get the singleton instance.- Returns:
Springleton
singleton- Throws:
IllegalStateException
- if no instance has been created yet
-
isContextRequired
public boolean isContextRequired()The implementation in
Springleton
always returns true.- Overrides:
isContextRequired
in classApplicationObjectSupport
-