IllegalStateException in TogglzFilter

1,144 views
Skip to first unread message

Steve Arch

unread,
Feb 20, 2014, 6:42:07 AM2/20/14
to togglz...@googlegroups.com
I'm trying to get togglz working in our servlets 3 project. We're using SpringMVC 3.2.

Following the instructions, the TogglzFilter class is instantiated and an IllegalStateException gets thrown at org.togglz.servlet.TogglzFilter.init(TogglzFilter.java:72:
Could not find any implementation of TogglzConfig or TogglzBootstrap. Please make sure that you have added the required integration modules to your project or register the implementation in your web.xml as described in the 'Configuration' chapter of the documentation.

I have created a TogglzConfiguration class (implementing TogglzConfig) and annotated it with @Component, but this class doesn't seem to get instantiated before TogglzFilter runs and the exception is thrown.
I'm running this (for testing) without a web.xml file and it gets this problem.

If I put in a web.xml file, then I still get the exception thrown when the Filter is initialised unless I explicitly put the config class in as a context-param (which the docs say you don't need to do in a servlets 3.0 environment):
    <context-param>
        <param-name>org.togglz.core.manager.TogglzConfig</param-name>
        <param-value>com.company.project.featureflags.TogglzConfiguration</param-value>
    </context-param>

I don't want to put it here as I want to inject our existing JDBC controller into the TogglzConfiguration component with spring to persist the feature states.

Any help would be really appreciated here!

Steve Arch

unread,
Feb 20, 2014, 7:04:47 AM2/20/14
to togglz...@googlegroups.com
Secondly, I have noticed that with component scanning, the TogglzConfiguration component gets instantiated twice during startup.
Is there any way to get the TogglzFilter to initialise after the spring context so that it picks up the TogglzConfiguration bean?

Christian Kaltepoth

unread,
Feb 20, 2014, 11:33:10 AM2/20/14
to togglz...@googlegroups.com
Hey Steve,

this really looks like an ordering issue. You could try to to use <absolute-ordering> in your web.xml to tell Spring to bootstrap prior to Togglz.

Another option would be to let Spring manage the FeatureManager lifecycle. You could either use FeatureManagerFactoryBean if you prefer XML configuration, or use FeatureManagerBuilder if you use the Java style configuration.

Let me know if this helps.

Christian



2014-02-20 13:04 GMT+01:00 Steve Arch <steve....@gmail.com>:
Secondly, I have noticed that with component scanning, the TogglzConfiguration component gets instantiated twice during startup.
Is there any way to get the TogglzFilter to initialise after the spring context so that it picks up the TogglzConfiguration bean?



Steve Arch

unread,
Feb 20, 2014, 11:38:18 AM2/20/14
to togglz...@googlegroups.com
Thanks for the reply. I spent most of today going at this. I tired the absolute-ordering, but it stopped the TogglzFilter loading unless explicitly stated (not what I was wanting).

It turned out that I didn't have the Spring integration listener in my web.xml:

    <listener>
        <!-- Spring integration required for Togglz -->
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

Once I had this in (and created an applicationContext.xml file that it wanted to read) it all worked quite easily. Maybe you could put a note in the Spring section of the quickstart guide about this?

Christian Kaltepoth

unread,
Feb 20, 2014, 11:39:42 AM2/20/14
to togglz...@googlegroups.com
Isn't the listener required for Spring to work correctly? Or is it optional?

Steve Arch

unread,
Feb 20, 2014, 11:46:29 AM2/20/14
to togglz...@googlegroups.com
I got strange behaviour without it (and didn't know that it was needed until I found it in it the demo project).

Without adding the listener, it would firstly load the TogglzFilter (and throw the exception). If you disabled the TogglzFilter (by having absolute-ordering or metadata-complete="true" in your web.xml) then it would load the TogglzConfig up. The problem that I had was that the Filter loaded first, and so couldn't find the config, threw an exception and the webapp didn't load.

If I manually specified
    <context-param>
        <param-name>org.togglz.core.manager.TogglzConfig</param-name>
        <param-value>com.company.project.featureflags.TogglzConfiguration</param-value>
    </context-param>
in my web.xml, then it would load the TogglzConfig first, then load the TogglzFilter (and not throw an exception) and would work. But I couldn't wire it with spring (eg, injecting the JDBC DataSource into the TogglzConfig object).

In short, it *will* work with some finessing without the spring listener, but not very well.

Christian Kaltepoth

unread,
Feb 20, 2014, 11:54:05 AM2/20/14
to togglz...@googlegroups.com
If you use the context parameter org.togglz.core.manager.TogglzConfig like shown your mail, you are basically telling Togglz: "If you don't find any other TogglzConfig, create an instance of this class and use it". So in this case Togglz creates the class instead of Spring. That's why dependency injection won't work for it.

Christian

nicks...@gmail.com

unread,
Aug 6, 2015, 9:06:03 AM8/6/15
to togglz-users
Christian,

I am facing similar issue. I am using 2.0.1.Final version of Togglz. I initially 

nicks...@gmail.com

unread,
Aug 6, 2015, 9:18:04 AM8/6/15
to togglz-users
Christian,

I am facing similar issue. I am using 2.0.1.Final version of Togglz. My application is already a Spring MVC application and Auto-wiring works fine. 
Initially implemented TogglzConfig using @Component on my class and deployed the application which gave me error "IllegalStateException - TogglzConfig filter not registered. Kindly implement Configuration class and register it."

If I manually specified 
    <context-param>
        <param-name>org.togglz.core.manager.TogglzConfig</param-name>
        <param-value>com.company.project.featureflags.TogglzConfiguration</param-value>
    </context-param>
in my web.xml, then it would load the TogglzConfig first, then load the TogglzFilter (and not throw an exception) and would work.

As per your comments it states that their is some ordering issue but I have tried all the ordering possible in web.xml and the result is error.

Why the TogglzConfig interface implementation is not working with @Component?
I have even tried giving @Configuration on the implementation class but still it results in error.

Kindly provide your inputs.

Thanks in advance.

Christian Kaltepoth

unread,
Aug 6, 2015, 11:36:15 AM8/6/15
to togglz...@googlegroups.com

Hey,

could you please post the full stack trace?

Christian

nicks...@gmail.com

unread,
Aug 8, 2015, 12:53:09 AM8/8/15
to togglz-users

StackTrace is pasted below


java.lang.IllegalStateException: Could not find any implementation of TogglzConfig or TogglzBootstrap. Please make sure that you have added the required integration modules to your project or register the implementation in your web.xml as described in the 'Configuration' chapter of the documentation.

       at org.togglz.core.bootstrap.FeatureManagerBootstrapper.createFeatureManager(FeatureManagerBootstrapper.java:73)

       at org.togglz.servlet.TogglzFilter.init(TogglzFilter.java:72)

Christian Kaltepoth

unread,
Aug 9, 2015, 7:39:02 AM8/9/15
to togglz...@googlegroups.com
First of all, you should really update to a more recent version of Togglz. Version 2.0.1.Final is very old. Try 2.2.0.Final instead.

If you are using @Component, you could also try to add this to your web.xml:

<context-param>
  <param-name>org.togglz.FEATURE_MANAGER_PROVIDED</param-name>
  <param-value>true</param-value>
</context-param>

This will basically prevent TogglzFilter from trying to bootstrap a FeatureManager itself. Actually this would work out of the box with current versions of Togglz, but it doesn't harm to tell it Togglz this way.

Christian

nicks...@gmail.com

unread,
Aug 10, 2015, 1:45:32 PM8/10/15
to togglz-users
I tried the approach suggested and it resulted in below mentioned error

Exception created : 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.

Christian Kaltepoth

unread,
Aug 10, 2015, 2:46:52 PM8/10/15
to togglz...@googlegroups.com

Could you include the full stack trace? Which version did you try?

nicks...@gmail.com

unread,
Aug 17, 2015, 10:37:32 AM8/17/15
to togglz-users
Exception created : 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:49)
at org.togglz.core.manager.LazyResolvingFeatureManager.getDelegate(LazyResolvingFeatureManager.java:21)
at org.togglz.core.manager.LazyResolvingFeatureManager.isActive(LazyResolvingFeatureManager.java:41)
at org.togglz.jsp.ActiveFeatureTag.isFeatureActive(ActiveFeatureTag.java:34)
at org.togglz.jsp.ActiveFeatureTag.doStartTag(ActiveFeatureTag.java:26)

nicks...@gmail.com

unread,
Aug 19, 2015, 10:20:39 AM8/19/15
to togglz-users
Any updates on below mentioned issue????

Sincerely need your help

Christian Kaltepoth

unread,
Aug 19, 2015, 12:32:51 PM8/19/15
to togglz...@googlegroups.com
I can see that this is NOT caused by some startup ordering issue. Like it can occur if Togglz starts up earlier than Spring.

Could you please share more of your configuration?
  • Which dependencies did you add to your project (with versions)?
  • What container are you using?
  • Did you add anything to web.xml
  • How does your TogglzConfig class look like (including annotations)
These details would be very helpful.

nicks...@gmail.com

unread,
Aug 26, 2015, 11:50:47 PM8/26/15
to togglz-users

  • Which dependencies did you add to your project (with versions)?
Ans togglz-spring

Christian Kaltepoth

unread,
Aug 27, 2015, 2:08:19 AM8/27/15
to togglz...@googlegroups.com
I cannot help you if you don't provide all configuration details.

You could have a look at the integration tests for Spring. These tests have been created to verify that TogglzConfig managed by Spring is picked up correctly.


You could also provide an minimal example application as a Maven project which demonstrates your problem.

Christian
Reply all
Reply to author
Forward
0 new messages