I'm trying to use the Togglz library which allows you to wrap your application logic and be able to toggle it ON or OFF, with some advanced strategies. I am going through the Spring Boot documentation for it, and although its quite concise, I'm finding it missing pieces of information that are not allowing me to test this properly.
reference: https://www.togglz.org/documentation/spring-boot-starter.html
- I am running a Spring Boot 2.4.5 version project and this documentation says to import the dependency, which I did:
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-boot-starter</artifactId>
<version>2.6.1.Final</version>
</dependency>
- The documentation then states you can use an auto-configuration class on your @RestController, like
@Controller
public class MyClass {
private FeatureManager manager;
public MyClass(FeatureManager manager) {
this.manager = manager;
}
@RequestMapping("/")
public ResponseEntity<?> index() {
if (manager.isActive(HELLO_WORLD)) {
...
}
}
}
Here is already where I had some questions that I didn't see explained, first, that are passing a enum "HELLO_WORLD" as an argument to this isActive()
function on the FeatureManager. I don't see how they are injecting this into the method/class. They do show how to declare the feature ENUM in the yaml, though, this is not referencing the "HELLO_WORLD" that was passed into the isActive() method mentioned previously, i.e. :
togglz:
features:
FOO:
enabled: true
BAR:
enabled: false
Further down the documentation, they finally do reference this HELLO_WORLD
enum, but I tried adding this to my application.yaml and I can't seem to figure out how they are injecting these Feature Enums into these methods:
togglz:
enabled: true # Enable Togglz for the application.
features: # The feature states. Only needed if feature states are stored in application properties.
HELLO_WORLD:
enabled: true
The documentation does explain how to create an enum class for these features, but they explictly list it as an alternative to defining it in the yaml file
public enum MyFeatures implements Feature {
@EnabledByDefault
@Label("First Feature")
FEATURE_ONE,
@Label("Second Feature")
FEATURE_TWO;
}
@Bean
public FeatureProvider featureProvider() {
return new EnumBasedFeatureProvider(MyFeatures.class);
}
I tried this also, and I just got more Bean exception errors when I try to run the Application, i.e.
Description:
Parameter 2 of method featureManager in org.togglz.spring.boot.autoconfigure.TogglzAutoConfiguration$FeatureManagerConfiguration required a bean of type 'org.togglz.core.user.UserProvider' that could not be found.
Action:
Consider defining a bean of type 'org.togglz.core.user.UserProvider' in your configuration.
Can anyone who has successful used this library provide input how to set a simple feature toggle ? Ultimately, I want to be able turn ON/OFF this feature while the application using a RELEASE DATE activation strategy i.e. 2021-06-30 00:00:00
such that I can have the toggle activate based on a datetime.
reference: https://www.togglz.org/documentation/activation-strategies.html
Can this be done in the yaml?