如何在Spring Boot应用程序中启用Togglz控制台

5

我的spring-boot+jersey应用程序已经集成了togglz。我按照以下方式添加了以下依赖项。

// togglz
compile('org.togglz:togglz-servlet:'+togglzVersion)
compile('org.togglz:togglz-cdi:'+togglzVersion)
compile('javax.enterprise:cdi-api:2.0-EDR1')
compile('org.togglz:togglz-spring-web:'+togglzVersion)
compile("org.togglz:togglz-spring-boot-starter:"+togglzVersion)
compile("org.togglz:togglz-console:"+togglzVersion)
compile("org.togglz:togglz-spring-security:"+togglzVersion)
compile("com.github.heneke.thymeleaf:thymeleaf-extras-togglz:1.0.1.RELEASE")

在我的启动类中,我添加了以下代码:

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

启动应用程序后,我可以从此链接(http://localhost:8080/togglz)看到JSON数据。 但我无法访问http://localhost:8080/togglz-console,出现“Failed to load resource: the server responded with a status of 403 (Forbidden”错误。
我的日志文件中记录了以下信息,但我无法访问togglz-console/*。
o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'togglzConsoleServlet' to [/togglz-console/*]

以下是我的Togglz属性文件:
# togglz
togglz:
    feature-enums: com.cooltoo.backend.features.AppFeatures # Comma-separated list of fully-qualified feature enum class names.
    features:
        SMS_CODE: false
    console:
        enabled: true # Enable admin console.
        path: /togglz-console # The path of the admin console when enabled.

我在这里错过了什么?
2个回答

5

步骤1:添加以下依赖项:

   <!-- Togglz Admin Console -->
    <dependency>
       <groupId>org.togglz</groupId>
       <artifactId>togglz-console</artifactId>
       <version>2.3.0.RC1</version>
   </dependency>

步骤2 在你的application.yml或者application.properties文件中添加以下内容:

togglz:
  console:
    enabled: true # Enable admin console.

或者

togglz.console.enabled: true # Enable admin console.

步骤3 通过以下方式配置控制台路径:

togglz:
    console:
     path: /togglz-console # The path of the admin console when enabled.

关于身份验证:添加一个虚拟的UserProvider,将管理员权限分配给每个用户:

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

如果您想对用户进行身份验证,而不是使用上述虚拟用户,请按照此文档实现自己的UserProvider。


我编辑了togglz属性设置,现在出现403禁止访问错误。 - Joey Yi Zhao

1
请在你的application.yml或application.properties文件中添加以下内容:
togglz:
  console:
    enabled: true
    path: /togglz-console
    use-management-port: false

或者

togglz.console.enabled: true
togglz.console.path: /togglz-console
togglz.console.use-management-port: false

将 togglz.console.use-management-port 设置为 false 将始终在应用程序端口上运行管理控制台。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接