Java 是否可以在非web应用程序中使用togglz
我试图找出是否可以在非web应用程序中使用togglz,就像我们有普通java项目或java批处理程序一样 我尝试在独立应用程序中添加togglz库,并尝试运行它 这是我的代码片段-Java 是否可以在非web应用程序中使用togglz,java,togglz,Java,Togglz,我试图找出是否可以在非web应用程序中使用togglz,就像我们有普通java项目或java批处理程序一样 我尝试在独立应用程序中添加togglz库,并尝试运行它 这是我的代码片段- import com.feature.MyFeature; public class Test { public static void main(String[] args) { Test t = new Test(); boolean valid=t.validat
import com.feature.MyFeature;
public class Test {
public static void main(String[] args) {
Test t = new Test();
boolean valid=t.validate("CREATE_TEAM");
System.out.println(valid);
}
public boolean validate(String feature){
if (MyFeature.valueOf(feature).isActive()) {
return true;
}
return false;
}
}
上面写着——
Exception in thread "main" 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 com.amdocs.switchlite.core.context.FeatureContext.getFeatureManager(FeatureContext.java:53)
at com.feature.MyFeature.isActive(MyFeature.java:20)
at Test.validate(Test.java:22)
at Test.main(Test.java:12)
您必须正确配置Togglz才能使其正常工作。在独立应用程序中,我建议使用以下设置 首先使用
FeatureManagerBuilder
创建一个FeatureManager
。大概是这样的:
FeatureManager featureManager = FeatureManagerBuilder.begin()
.featureEnum(Features.class)
.stateRepository(new InMemoryStateRepository())
.userProvider(new NoOpUserProvider())
.build();
告诉您的经理的StaticFeatureManager提供程序:
StaticFeatureManagerProvider.setFeatureManager(featureManager);
现在,StaticFeatureManagerProvider
可以告诉Togglz您的FeatureManager
了,一切都应该正常
Features.FOOBAR.isActive();
// > false
我们可以看看您的pom.xml吗?使用的依赖项是什么?我们也可以看看你的togglz配置。