Spring Boot Togglz - 没有UserProvider类型的限定bean错误

时间:2016-12-21 12:57:52

标签: java spring spring-boot togglz

我正在尝试将togglz添加到我的sprint启动应用程序中,但是在启动时我收到以下错误:

2016-12-21 12:41:34.482 ERROR 43583 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context: org.springframework.beans.factory.UnsatisfiedDependencyException
2016-12-21 12:41:34.530  WARN 43583 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.togglz.core.user.UserProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    ... 138 common frames omitted
Wrapped by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'featureManager' defined in class path resource [org/togglz/spring/boot/autoconfigure/TogglzAutoConfiguration$FeatureManagerConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 2 of type [org.togglz.core.user.UserProvider]: : No qualifying bean of type [org.togglz.core.user.UserProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.togglz.core.user.UserProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

似乎配置中存在问题,但我似乎按照https://www.togglz.org/documentation/spring-boot-starter.html

的建议准备好了所有内容

我的设置如下:

package com.togglz;

import java.io.File;

import org.springframework.stereotype.Component;
import org.togglz.core.Feature;
import org.togglz.core.manager.TogglzConfig;
import org.togglz.core.repository.StateRepository;
import org.togglz.core.repository.file.FileBasedStateRepository;
import org.togglz.core.user.FeatureUser;
import org.togglz.core.user.SimpleFeatureUser;
import org.togglz.core.user.UserProvider;

@Component
public class TogglzConfiguration implements TogglzConfig {

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

    public StateRepository getStateRepository() {
        return new FileBasedStateRepository(new File("application-local.properties"));
    }

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

    }
}

package com.togglz;

import org.springframework.stereotype.Component;
import org.togglz.core.Feature;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;


    @Component
    public enum Features implements Feature {

        @Label("Feature1")
        FEATURE_ONE,

        @Label("Feature2")
        FEATURE_TWO;

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

我的应用程序属性文件包含以下内容:

togglz:
  enabled: true
  feature-enums: com.togglz.Features
    FEATURE_ONE: true
    FEATURE_TWO: false

是否有其他人遇到此问题或有任何想法如何解决?我原本期望我的getUserProvider()处理事情,但可能不会......

2 个答案:

答案 0 :(得分:0)

看起来像Spring Boot版本的升级就行了......

答案 1 :(得分:0)

您在@Bean函数上缺少 public UserProvider getUserProvider() {}注解,这是一个问题。

Spring正在尝试搜索togglz配置其用户提供程序所需的userprovider bean