简体   繁体   English

示例 keycloak spring-boot 应用程序无法找到 bean KeycloakSpringBootConfigResolver

[英]Example keycloak spring-boot app fails to find bean KeycloakSpringBootConfigResolver

I'm trying to run example app from:我正在尝试从以下位置运行示例应用程序:

https://github.com/keycloak/keycloak-quickstarts/tree/latest/app-springboot https://github.com/keycloak/keycloak-quickstarts/tree/latest/app-springboot

I'm getting error:我收到错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method setKeycloakSpringBootProperties in org.keycloak.adapters.springboot.KeycloakBaseSpringBootConfiguration required a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' that could not be found.


Action:

Consider defining a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' in your configuration.


Process finished with exit code 1

I don't have a solution at the moment, but I can see that the exact same issue has been registered on the Keycloak Jira a couple of months ago: https://issues.jboss.org/browse/KEYCLOAK-10595 .我目前没有解决方案,但我可以看到几个月前在 Keycloak Jira 上注册了完全相同的问题: https ://issues.jboss.org/browse/KEYCLOAK-10595。 The problem seems to be caused by the code delivered with this PR: https://github.com/keycloak/keycloak/pull/6075 .这个问题似乎是由这个 PR 提供的代码引起的: https : //github.com/keycloak/keycloak/pull/6075

The author of the PR described the problem in this way: "The only remaining problem is, that the resolver is usually contained in the configuration using the KeycloakAutoConfiguration (in my example the SharedConfiguration) so you are trying to access the bean while the configuration is stil being created. This can be solved by moving the resolver bean into another configuration which has to be loaded before the KeycloakAutoConfiguration." PR 的作者以这种方式描述了这个问题:“唯一剩下的问题是,解析器通常包含在使用 KeycloakAutoConfiguration(在我的示例中为 SharedConfiguration)的配置中,因此您试图在配置时访问 bean仍在创建中。这可以通过将解析器 bean 移动到另一个必须在 KeycloakAutoConfiguration 之前加载的配置中来解决。” (source: https://issues.jboss.org/browse/KEYCLOAK-10334?focusedCommentId=13738518&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13738518 ) (来源: https : //issues.jboss.org/browse/KEYCLOAK-10334?focusedCommentId=13738518&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13738518


UPDATE (OLD)更新(旧)

On the issue from the Keycloak Jira ( https://issues.jboss.org/browse/KEYCLOAK-11282 ), a temporary workaround has been suggested.关于 Keycloak Jira ( https://issues.jboss.org/browse/KEYCLOAK-11282 ) 的问题,已建议临时解决方法。

@Configuration
public class MyKeycloakSpringBootConfigResolver extends KeycloakSpringBootConfigResolver {
    private final KeycloakDeployment keycloakDeployment;

    public MyKeycloakSpringBootConfigResolver(KeycloakSpringBootProperties properties) {
        keycloakDeployment = KeycloakDeploymentBuilder.build(properties);
    }

    @Override
    public KeycloakDeployment resolve(HttpFacade.Request facade) {
        return keycloakDeployment;
    }
}

LATEST UPDATE最新更新

A simpler way to solve the problem is to declare a KeycloakSpringBootConfigResolver in a separate configuration class.更简单的解决方法是在单独的配置类中声明一个KeycloakSpringBootConfigResolver This option will fix issues with both Spring Boot and Spring Security.此选项将解决 Spring Boot 和 Spring Security 的问题。

@Configuration
public class KeycloakConfig {

    @Bean
    public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
        return new KeycloakSpringBootConfigResolver();
    }
}

I don't have an actual answer to solve this, but I do see there is a similar bug on the Keycloak issue tracker for another quickstart. 我没有解决这个问题的实际答案,但是我确实看到Keycloak问题跟踪器上存在类似的错误,可用于另一个快速入门。 https://issues.jboss.org/browse/KEYCLOAK-11218 https://issues.jboss.org/browse/KEYCLOAK-11218

I was also able to reproduce the same failure you see by cloning that project and trying to run it. 通过克隆该项目并尝试运行它,我还能够重现您看到的相同故障。 You may want to create a ticket for this quickstart project, in case they have missed that the issue affects multiple quickstarts. 您可能想为此快速入门项目创建一个票证,以防他们错过了影响多个快速入门的问题。

I did try defining a bean of that type, but that leads to other runtime errors about other unsatisfied dependencies. 我确实尝试定义了这种类型的bean,但这会导致有关其他未满足的依赖关系的其他运行时错误。

Thomas answer did work for me.托马斯的回答对我有用。 The keycloak spring boot properties class had to be enabled manually though, by annotating the Application class like this:但是,必须通过像这样注释 Application 类来手动启用 keycloak spring boot 属性类:

@EnableConfigurationProperties(KeycloakSpringBootProperties.class)

Furthermore the custom keycloak spring boot config resolver bean must be overriden explicitly.此外,必须显式覆盖自定义 keycloak spring boot 配置解析器 bean。

@Bean
@Primary
public KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties properties) {
      return new MyKeycloakSpringBootConfigResolver(properties);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM