gpt4 book ai didi

spring-boot - 如何在 spring-boot 应用程序中启用 togglz-console

转载 作者:行者123 更新时间:2023-12-04 02:33:52 35 4
gpt4 key购买 nike

我的 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.

我在这里错过了什么?

最佳答案

第一步 添加以下依赖项:

   <!-- 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.

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

关于spring-boot - 如何在 spring-boot 应用程序中启用 togglz-console,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36352832/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com