Ok, great... Some debugging in SpringWebBeanFinder may help here...
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
public class SpringWebBeanFinder implements BeanFinder {
@Override
public <T> Collection<T> find(Class<T> clazz, Object context) {
Collection<T> result = new ArrayList<T>();
// use the Spring API to obtain the WebApplicationContext
WebApplicationContext applicationContext = null;
if (context instanceof ServletContext) {
applicationContext = WebApplicationContextUtils.getWebApplicationContext((ServletContext) context);
}
if (applicationContext == null) {
applicationContext = ContextLoader.getCurrentWebApplicationContext();
}
Collection<FeatureManager> result = beanFinder.find(FeatureManager.class, null);
applicationContext = ContextLoader.getCurrentWebApplicationContext();
WebApplicationContextUtils.getWebApplicationContext((ServletContext) context);
public class BeanFinderFeatureManagerProvider implements FeatureManagerProvider {
@Override
public int priority() {
return 60;
}
@Override
public FeatureManager getFeatureManager() {
// we _may_ find multiple managers, which will lead to an error
Set<FeatureManager> managers = new HashSet<FeatureManager>();
// ask all providers for managed FeatureManager
for (BeanFinder beanFinder : ServiceLoader.load(BeanFinder.class)) {
Collection<FeatureManager> result = beanFinder.find(FeatureManager.class, null);
if (result != null) {
managers.addAll(result);
}
}
public class TogglzApplicationListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
ContextClassLoaderApplicationContextHolder.bind(applicationContext);
} else if (event instanceof ContextClosedEvent) {
ContextClassLoaderApplicationContextHolder.release();
}
}
}
I have a custom FeatureManager that I initiate via Spring's Java Config.
With Spring Boot running in IBM WAS 8 I could only make it work with StaticFeatureManagerProvider and FEATURE_MANAGER_PROVIDED=true, otherwise Togglz just can't discover my Spring initiated feature manager.Spring Boot standalone works just fine without either of those hacks.