forked from Netflix/governator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-with-spring.txt
More file actions
27 lines (19 loc) · 880 Bytes
/
Copy pathusing-with-spring.txt
File metadata and controls
27 lines (19 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Governator can be used in a Spring project in the following way:
* Create a LifeCycleListener that has access to your ApplicationContext
LifecycleListener lifecycleListener = new LifecycleListener()
{
@Override
public void objectInjected(Object obj)
{
// context is an ApplicationContext
context.getBeanFactory().registerSingleton(obj.getClass().getName(), obj);
}
@Override
public void stateChanged(Object obj, LifecycleState newState)
{
}
};
* Include the listener when creating the LifecycleInjector:
.withLifecycleListener(new FilteredLifecycleListener(lifecycleListener, yourPackages))
* You can then access Governator managed objects via:
MyClass m = context.getBeanFactory().getBean(MyClass.class);