我一直收到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 app运行正常,但是当我尝试转到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]
答案 0 :(得分:1)
如果您处于普通的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);
}
}
一个典型的例子如下:
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();
}
}
在普通的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>
我希望这有帮助。如果这仍然无效,请在您的问题中包含完整的堆栈跟踪。