public class ApplicationContext extends Object
The ApplicationContext houses all your beans. You load it by supplying any object you want to the ApplicationContext#registerBeans() method.
All methods in the beanProvider object is concidered beans, and will be instantiated lazily unless you annotate then with @Eager. You don't need to implement an interface, and the methods in the beanProvider can have any visibility you want. The method name is the bean name.
Your beans can be automatically injected with other beans from your ApplicationContext if you annotate the fields with the @Inject annotation. Circular dependencies are allowed. You can supply the bean-argument to the @Inject annotation if you want to inject a spesific bean based on name. If you don't, the best matching object based on type and name of the field will be injected.
You can even inject beans that are not part of your ApplicationContext via the ApplicationContext.inject(object) method. Any @Inject annotated field will be injected.
For more information, see these annotations:
| Constructor and Description |
|---|
ApplicationContext() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getBean(Class<T> className)
Get a bean from the ApplicationContext via className.
|
static Object |
getBean(String beanName)
Manually get a bean from the ApplicationContext via bean name.
|
static BeanInfo |
getBeanInfo(String beanName)
Get the BeanInfo object, containing various information about a bean, including the bean.
|
static List<BeanInfo> |
getBeanInfos(Class className)
Get all BeanInfo objects for the supplied class
|
static <T> List<T> |
getBeans(Class<T> className)
Get all beans of the supplied class
|
static <T> T |
getService(Class<T> serviceClass) |
static <T> T |
getService(Class<T> serviceClass,
int timeout) |
static <T> T |
getService(Class<T> serviceClass,
int timeout,
String options) |
static void |
inject(Object object)
Inject beans from the ApplicationContext into an arbitrary object that is not
part of the ApplicationContext.
|
static void |
installShutdownHook() |
static void |
registerBeans(Object beanProvider)
Register beans into your ApplicationContext.
|
static void |
shutdown() |
public static void registerBeans(Object beanProvider)
beanProvider - An object that provides beans for your ApplicationContext.
For more information:
ApplicationContextpublic static void installShutdownHook()
public static Object getBean(String beanName)
beanName - The name of the bean you wantpublic static <T> T getBean(Class<T> className)
Get a bean from the ApplicationContext via className.
If more beans of same class exists, the first is returned.
T - The bean typeclassName - The class name of the bean you wantpublic static BeanInfo getBeanInfo(String beanName)
beanName - The name of the bean you want the BeanInfo forpublic static <T> List<T> getBeans(Class<T> className)
T - the bean typeclassName - The class name of the beans you wantpublic static List<BeanInfo> getBeanInfos(Class className)
className - The class name of the BeanInfos you wantpublic static void inject(Object object)
object - The object you want to inject with members from the ApplicationContextpublic static <T> T getService(Class<T> serviceClass)
public static <T> T getService(Class<T> serviceClass, int timeout)
public static void shutdown()
Copyright © 2011-2013 SYSE. All Rights Reserved.