0

I have a large Spring application that is set up without XML using only annotations. I have made some changes to this application and have a separate project with what should be almost all the same code. However, in this separate project, Togglz seems to be using some sort of default config instead of the TogglzConfig file I've set up.

The first sign that something was wrong was when I couldn't access the Togglz console. I get a 403 Forbidden error despite my config being set to allow anyone to use it (as shown on the Togglz site). I then did some tests and tried to see a list of features and the list is empty when I call FeatureContext.getFeatureManager().getFeatures() despite my Feature class having several features included. This is why I think it's using some sort of default.

TogglzConfiguration.java

public enum Features implements Feature {

  FEATURE1,

  FEATURE2,

  FEATURE3,

  FEATURE4,

  FEATURE5;

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

TogglzConfiguration.java

@Component
public class TogglzConfiguration implements TogglzConfig {

  public Class<? extends Feature> getFeatureClass() {
    return Features.class;
  }

  public StateRepository getStateRepository() {
    File properties = [internal call to property file];
    try {
      return new FileBasedStateRepository(properties);
    } catch (Exception e) {
      throw new TogglzConfigException("Error getting Togglz configuration from " + properties + ".", e);
    }
  }

  @Override
  public UserProvider getUserProvider() {
    return new UserProvider() {
      @Override
      public FeatureUser getCurrentUser() {
        return new SimpleFeatureUser("admin", true);
      }
    };
  }
}

SpringConfiguration.java

@EnableTransactionManagement
@Configuration
@ComponentScan(basePackages = { "root package for the entire project" }, excludeFilters =
    @ComponentScan.Filter(type=FilterType.ANNOTATION, value=Controller.class))
public class SpringConfiguration {

    @Bean
    public TransformerFactory transformerFactory() {
        return TransformerFactory.newInstance();
    }

    @Bean
    public DocumentBuilderFactory documentBuilderfactory() {
        return DocumentBuilderFactory.newInstance();
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

My project finds a bunch of other beans set up with the @Component annotation. I don't know if the problem is that this component isn't being picked up at all or if Togglz simply isn't using it for some reason. I tried printing the name of the FeatureManager returned by FeatureContext.getFeaturemanager() and it is FallbackTestFeatureManager so this seems to confirm my suspicion that it's just not using my config at all.

Anyone have any ideas on what I can check? I'm flat out of ideas, especially since this is working with an almost completely the same IntelliJ project on my machine right now. I just can't find out what's different about the Togglz setup or the Spring configurations. Thanks in advance for your help.

user2271605
  • 95
  • 1
  • 9

1 Answers1

1

I finally had my light bulb moment and solved this problem. In case anyone else has a similar issue, it seems my mistake was having the Togglz testing and JUnit dependencies added to my project but not limiting them to the test scope. I overlooked that part of the site.

<!-- Togglz testing support -->
<dependency>
  <groupId>org.togglz</groupId>
  <artifactId>togglz-testing</artifactId>
  <version>2.5.0.Final</version>
  <scope>test</scope>
</dependency>

Without that scope, I assume these were overriding the Togglz configuration I created with a default test configuration and that was causing my issue.

user2271605
  • 95
  • 1
  • 9