Gradle dependencies:
compile('org.springframework.boot:spring-boot-starter-web')
compile 'org.togglz:togglz-servlet:2.0.1.Final'
compile("org.togglz:togglz-console:2.3.0.RC1")
compile("org.togglz:togglz-spring-security:2.3.0.RC1")
compile("com.github.heneke.thymeleaf:thymeleaf-extras-togglz:1.0.1.RELEASE")
compile('org.springframework.boot:spring-boot-starter-actuator')
testCompile("org.togglz:togglz-junit:2.3.0.RC1")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile(group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5')
Features enum:
/**
* Sample features for this demo.
*/
public enum DemoFeature implements Feature
{
@EnabledByDefault
@Label("First Feature is enabled by default")
FEATURE_ONE,
@Label("Second Feature")
FEATURE_TWO,
@Label("Third Feature")
FEATURE_THREE;
public boolean isActive()
{
return FeatureManagerWrapper.getInstance().getFeatureManager().isActive(this);
}
}
Application:
@EnableAutoConfiguration
@Configuration
@ComponentScan
public class StatusApplication
{
public static void main(String[] args)
{
SpringApplication.run(StatusApplication.class, args);
}
@Bean
public FeatureManagerWrapper featureManagerWrapper()
throws IOException
{
final FeatureManagerBuilder builder = new FeatureManagerBuilder();
builder.name("demo-feature-manager").featureEnum(DemoFeature.class).stateRepository(stateRepository())
.userProvider(userProvider());
final FeatureManager featureManager = builder.build();
final FeatureManagerWrapper featureManagerWrapper = FeatureManagerWrapper.getInstance();
featureManagerWrapper.setFeatureManager(featureManager);
return featureManagerWrapper;
}
@Bean
public StateRepository stateRepository()
throws IOException
{
return new FileBasedStateRepository(new File("src/main/resources/application.properties"));
}
@Bean
public UserProvider userProvider()
{
return new UserProvider()
{
@Override
public FeatureUser getCurrentUser()
{
return new SimpleFeatureUser("admin", true);
}
};
}
}
FeatureManagerWrapper:
public class FeatureManagerWrapper {
private FeatureManager featureManager;
private static final FeatureManagerWrapper instance = new FeatureManagerWrapper();
private FeatureManagerWrapper() {
// singleton
}
public static FeatureManagerWrapper getInstance() {
return instance;
}
public void setFeatureManager(FeatureManager featureManager) {
if(this.featureManager == null) {
this.featureManager = featureManager;
} else {
throw new UnsupportedOperationException("featureManager is already set, cannot reset.");
}
}
public FeatureManager getFeatureManager() {
return featureManager;
}
}
Application.properties:
togglz:
enabled: true
feature-enums: com.test.DemoFeature
feature-manager-name:
features:
FEATURE_ONE: false
FEATURE_TWO: true
FEATURE_THREE: false
features-file:
features-file-min-check-interval:
cache:
enabled: false
time-to-live: 0
time-unit: milliseconds
console:
enabled: true
path: /togglz-console
feature-admin-authority:
secured: false
endpoint:
id: togglz
enabled: true
sensitive: true