我不断收到IllegalStateException:在Maven上的Web应用程序中安装togglz时找不到FeatureManager。我完全遵循了这些指示。在我的maven应用程序中,我的pom.xml文件具有以下设置:
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-console</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-servlet</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
以及web.xml文件中的以下内容:
<context-param>
<param-name>org.togglz.core.manager.TogglzConfig</param-name>
<param-value>com.test.test.ana.FeatureFlagConfiguration</param-value>
</context-param>
<servlet>
<servlet-name>TogglzConsoleServlet</servlet-name>
<servlet-class>org.togglz.console.TogglzConsoleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TogglzConsoleServlet</servlet-name>
<url-pattern>/togglz/*</url-pattern>
</servlet-mapping>
该示例maven应用运行良好,但是当我尝试转到togglz虚拟目录时,它抛出IllegalStateException:找不到FeatureManager错误,它没有提供更多细节。关于该错误真正含义的任何建议?
我只是想获得一个使用togglz的示例项目。我不能使用spring或cdi,只能使用servlet。 (是的,我已经配置了Servlet 3.0)
提前致谢,
编辑:这是确切的堆栈跟踪:
[ERROR ] SRVE0777E: Exception thrown by application class 'org.togglz.core.context.FeatureContext.getFeatureManager:49'
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:24)
at org.togglz.core.manager.LazyResolvingFeatureManager.getCurrentFeatureUser(LazyResolvingFeatureManager.java:49)
at org.togglz.console.TogglzConsoleServlet.isFeatureAdmin(TogglzConsoleServlet.java:68)
at org.togglz.console.TogglzConsoleServlet.service(TogglzConsoleServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1285)
at [internal classes]
最佳答案
如果您在普通的Servlet环境中,则在添加Maven依赖项后必须执行以下操作:
实施您的功能枚举
通常看起来像这样:
public enum MyFeatures implements Feature {
@EnabledByDefault
@Label("First Feature")
FEATURE_ONE,
@Label("Second Feature")
FEATURE_TWO;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}
通过实现TogglzConfig来配置Togglz
一个典型的示例如下所示:
public class MyTogglzConfiguration implements TogglzConfig {
public Class<? extends Feature> getFeatureClass() {
return MyFeatures.class;
}
public StateRepository getStateRepository() {
return new FileBasedStateRepository(new File("/tmp/features.properties"));
}
public UserProvider getUserProvider() {
return new ServletUserProvider();
}
}
在web.xml中注册您的配置类
在普通的Servlet环境中,您现在必须通过将以下内容添加到web.xml中来注册TogglzConfig实现:
<context-param>
<param-name>org.togglz.core.manager.TogglzConfig</param-name>
<param-value>com.example.myapp.MyTogglzConfiguration</param-value>
</context-param>
您还应该明确告诉Togglz,您不希望它从Spring或CDI查找FeatureManager,而是创建和管理实例本身:
<context-param>
<param-name>org.togglz.FEATURE_MANAGER_PROVIDED</param-name>
<param-value>true</param-value>
</context-param>
在Servlet 3.0环境中,通常会自动拾取TogglzFilter。但是,您也可以手动注册:
<filter>
<filter-name>TogglzFilter</filter-name>
<filter-class>org.togglz.servlet.TogglzFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TogglzFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
希望对您有所帮助。如果仍然无法解决问题,请在问题中包含完整的stacktrace。
关于java - Togglz引发IllegalStateException错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30360224/