【问题标题】:How to enable togglz-console in spring-boot application如何在 spring-boot 应用程序中启用 togglz-console
【发布时间】:2016-07-21 01:17:31
【问题描述】:

我的 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);
}

启动应用程序后,我可以从这个链接看到 json 数据:http://localhost:8080/togglz。 但我无法访问http://localhost:8080/togglz-console。我收到“加载资源失败:服务器响应状态为 403(禁止”错误)。

我可以在下面看到登录我的日志文件,但我无法访问 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.

我错过了什么?

【问题讨论】:

    标签: spring-boot jersey togglz


    【解决方案1】:

    Step1 添加以下依赖:

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

    Step2 在您的 application.yml 或 application.properties 中添加以下内容

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

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

    Step3配置控制台路径

    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);
                    }
                };
            }
        }
    

    如果你想对用户进行身份验证,而不是上面的虚拟用户,请按照 documentation 实现你自己的 UserProvider

    【讨论】:

    • 我编辑了 togglz 属性设置,现在我收到 403 Forbidden 错误。
    【解决方案2】:

    请在您的 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 将始终在应用程序端口上运行管理控制台。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 2021-03-25
      • 2021-02-05
      • 2020-06-22
      相关资源
      最近更新 更多