2017-02-17 7 views
1

togglzを非ウェブアプリケーションで使用することが可能かどうかを調べようとしています。普通のJavaプロジェクトやJavaバッチプログラムがあります。非ウェブアプリケーションでtogglzを使用することが可能です

私はスタンドアロンアプリケーションでtogglzライブラリを追加しようとしましたが、それを実行しようとしました。

これは私のコードスニペットである -

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) 
+0

pom.xmlがある場合は表示できますか?使用される依存関係は何ですか?あなたのtogglz設定を見ることもできますか? –

答えて

3

あなたはそれを動作させるために正しくTogglzを設定する必要があります。スタンドアロンアプリケーションでは、次の設定をお勧めします。

FeatureManagerBuilderを使用して最初にFeatureManagerを作成します。このような何か:

FeatureManager featureManager = FeatureManagerBuilder.begin() 
     .featureEnum(Features.class) 
     .stateRepository(new InMemoryStateRepository()) 
     .userProvider(new NoOpUserProvider()) 
     .build(); 

上司についてStaticFeatureManagerProviderを教えて:

StaticFeatureManagerProvider.setFeatureManager(featureManager); 

StaticFeatureManagerProviderはあなたのFeatureManagerについてTogglzを伝えることができ、すべてが正常に動作する必要があります!

Features.FOOBAR.isActive(); 
// > false 
+0

これは必要に応じて正確に動作します、ありがとう@chkal –

関連する問題