将 Togglz 与我的 Spring MVC 应用程序集成时,我遇到了异常。
例外
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.
org.togglz.core.context.FeatureContext.getFeatureManager(FeatureContext.java:53)
org.togglz.core.manager.LazyResolvingFeatureManager.getDelegate(LazyResolvingFeatureManager.java:24)
org.togglz.core.manager.LazyResolvingFeatureManager.getCurrentFeatureUser(LazyResolvingFeatureManager.java:49)
org.togglz.console.TogglzConsoleServlet.isFeatureAdmin(TogglzConsoleServlet.java:75)
org.togglz.console.TogglzConsoleServlet.service(TogglzConsoleServlet.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.togglz.servlet.TogglzFilter.doFilter(TogglzFilter.java:100)
以下依赖项在 Maven 中定义 -
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
<version>2.3.0.Final</version>
</dependency>
<!-- Spring integration (optional) -->
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-web</artifactId>
<version>2.3.0.Final</version>
</dependency>
<!-- Togglz Admin Console -->
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-console</artifactId>
<version>2.3.0.Final</version>
</dependency>
我的配置类 -
@Component
public class MyTogglzConfiguration implements TogglzConfig {
/* ..... */
@Override
public UserProvider getUserProvider() {
return new UserProvider() {
@Override
public FeatureUser getCurrentUser() {
return new SimpleFeatureUser("admin", true);
}
};
}
@Override
public Class<? extends Feature> getFeatureClass() {
// TODO Auto-generated method stub
return MyFeatures.class;
}
@Override
public StateRepository getStateRepository() {
// TODO Auto-generated method stub
return new FileBasedStateRepository(new File("c:/tmp/features.properties"));
}
}
我的功能类-
public enum MyFeatures implements Feature {
@Label("First Feature")
FEATURE_ONE,
@EnabledByDefault
@Label("Second Feature")
FEATURE_TWO;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}
上面的配置应该可以工作,但我得到的是“java.lang.IllegalStateException:找不到 TogglzConfig 或 TogglzBootstrap 的任何实现”。添加以下上下文参数后,此错误消失了,但现在我有“找不到 FeatureManager”
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) {
servletContext.setInitParameter("org.togglz.FEATURE_MANAGER_PROVIDED", "true");
}
}