1

I have tried to integrate togglz into my Spring Boot app, however it looks as though Auto Configuration has difficulty providing a FeatureManager. The following is my stack trace:

2017-02-23 16:04:30.033 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No cached FeatureManager for class loader: org.springframework.boot.devtools.restart.classloader.RestartClassLoader@6b8005f1
2017-02-23 16:05:57.403 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : Found 5 FeatureManagerProvider implementations...
2017-02-23 16:06:27.652 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No FeatureManager provided by org.togglz.core.context.ThreadLocalFeatureManagerProvider
2017-02-23 16:06:36.436 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No FeatureManager provided by org.togglz.core.context.BeanFinderFeatureManagerProvider
2017-02-23 16:06:45.980 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No FeatureManager provided by org.togglz.core.context.StaticFeatureManagerProvider
2017-02-23 16:06:51.164 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No FeatureManager provided by org.togglz.core.context.ContextClassLoaderFeatureManagerProvider
2017-02-23 16:06:55.980 DEBUG [myService,,,] 23359 --- [  restartedMain] o.t.c.c.JNDIFeatureManagerProvider       : FeatureMananger not found: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
2017-02-23 16:06:57.990 DEBUG [myService,,,] 23359 --- [  restartedMain] org.togglz.core.context.FeatureContext   : No FeatureManager provided by org.togglz.core.context.JNDIFeatureManagerProvider

with the app eventually dying with an IllegalStateException:

Caused by: java.lang.IllegalStateException: Could not find the FeatureManager. For web applications please verify that the TogglzFilter starts up correctly. In other deployment scenarios you will typically have to implement a FeatureManagerProvider as described in the 'Advanced Configuration' chapter of the documentation.
    at org.togglz.core.context.FeatureContext.getFeatureManager(FeatureContext.java:53) ~[togglz-core-2.3.0.Final.jar:na]

I have the togglz.enabled and my togglz.feature-enums properties defined in my app properties, as well as my Configuration class implementing TogglzConfig created, it just seems to be whatever Spring Boot is doing behind the scenes with togglz is not quite working. Has anyone else came across this or know how to fix?

deanmau5
  • 861
  • 7
  • 17
  • 27
  • can you share the code and how you are setting up this? – xiumeteo Feb 23 '17 at 16:44
  • It looks like it's occurring as I'm putting a togglz isActive check in a constructor. I have a DocumentBuilder() constructor and in there am doing a toggle check, when DocumentBuilder() is instantiated elsewhere, the aforementioned error occurs. If I move the togglz isActive check to a build() method in DocumentBuilder, things work fine. – deanmau5 Feb 23 '17 at 16:54
  • How are you using those classes, can you share those chunks of code? – xiumeteo Feb 23 '17 at 23:43

1 Answers1

1

First, I recommend you update your post to include:

  • Spring boot configuration
  • Minimal Feature Enumeration
  • pom.xml

Note if you're using spring boot you should be using the following GAVs:

<dependency>
    <groupId>org.togglz</groupId>
    <artifactId>togglz-spring-boot-starter</artifactId>
    <version>2.4.1.Final</version>
</dependency>
<dependency>
    <groupId>org.togglz</groupId>
    <artifactId>togglz-console</artifactId>
    <version>2.4.1.Final</version>
</dependency>

Then it should be as simple as defining beans that return:

  • StateRepository
  • FeatureProvider
  • UserProvider

A simple implementation of this would be:

@Bean
public StateRepository getStateRepository() {
    return new InMemoryStateRepository()
}

@Bean
public FeatureProvider featureProvider() {
    return new EnumBasedFeatureProvider(MyFeatures.class);
}

@Bean
public UserProvider getUserProvider() {
    return new NoOpUserProvider();
}

Where MyFeatures.class is an enumeration that implements Feature

Other properties that may be beneficial for you to set for spring boot include:

togglz.console.enabled=true
togglz.console.secured=false
Russ
  • 1,996
  • 3
  • 19
  • 31