Search code examples
spring-bootyamlspring-boot-startertogglz

Togglz don't pick up Spring-Boot configuration from application.yml


I tried to follow the Togglz guide for Spring Boot, so added all necessary dependencies, created a feature enum:

public enum RetrospectiveBoardFeatures implements Feature {

    @Label("Name by cookie")
    NAME_BY_COOKIE,

    @Label("Name by login")
    NAME_BY_LOGIN;

    public boolean isActive() {
        return FeatureContext.getFeatureManager().isActive(this);
    }
}

, configured a EnumBasedFeatureProvider to make that enum known to Spring/Togglz:

@SpringBootApplication
public class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public FeatureProvider featureProvider() {
        return new EnumBasedFeatureProvider(RetrospectiveBoardFeatures.class);
    }
}

This all works fine until I wrote a small unit test to see if the feature toggle configuration is applied to my enum (from application.yml):

togglz:
  features:
    NAME_BY_COOKIE:
      enabled: true
    NAME_BY_LOGIN:
      enabled: false

Test:

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = Application.class)
public class RetrospetiveBoardFeaturesTest {
    @Test
    public void testCookieFeature() {
        assertThat(RetrospetiveBoardFeatures.NAME_BY_COOKIE.isActive(), is(true));
    }
}

So my expected result was not met (feature active). Then I added the enabled by default annotation and my feature got active. According to the guide (how I understood it) I don't need to add anything that reads my configuration from Spring and make them known to Togglz. The Togglz samples on GitHub also didn't do anything in this regard (and by looking what Togglz provide in the Spring-Boot starter there is a feature property provider already set up). Maybe I have some wrong versions selected (Spring boot 2.0.1.RELEASE and Togglz 2.5.0.Final)? What did I wrong?


Solution

  • Togglz 2.5.0.Final doesn't support Spring Boot 2 yet. I guess this may be the source of your problem. We are about to release 2.6.0.Final with full Spring Boot 2 support in the next days.

    Of course you could give the latest snapshot a try. See all the details here:

    https://www.togglz.org/download.html

    Also, feel free to join our Gitter chat where we currently discuss all the issue regarding Spring Boot 2 support:

    https://gitter.im/togglz/togglz