示例键斗弹簧启动应用找不到 Bean 键斗篷弹簧靴配置解析器

2022-09-01 17:13:06

我正在尝试从以下位置运行示例应用:

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

我收到错误:

***************************
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

答案 1

我目前没有解决方案,但我可以看到几个月前在Keycloak Jira上注册了完全相同的问题:https://issues.jboss.org/browse/KEYCLOAK-10595。问题似乎是由此 PR 提供的代码引起的:https://github.com/keycloak/keycloak/pull/6075

PR的作者以这种方式描述了这个问题:“唯一剩下的问题是,解析器通常包含在使用KeycloakAutoConfiguration(在我的示例中是ShareConfiguration)的配置中,因此您正在尝试在创建配置时访问Bean。这可以通过将解析器bean移动到另一个配置中来解决,该配置必须在KeycloakAutoConfiguration之前加载。(资料来源:https://issues.jboss.org/browse/KEYCLOAK-10334?focusedCommentId=13738518&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13738518)


更新(旧)

关于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;
    }
}

最新更新

解决此问题的更简单方法是在单独的配置类中声明 。此选项将修复Spring Boot和Spring Security的问题。KeycloakSpringBootConfigResolver

@Configuration
public class KeycloakConfig {

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

答案 2

托马斯的答案确实对我有用。但是,必须手动启用键斗弹启动属性类,方法是对 Application 类进行注释,如下所示:

@EnableConfigurationProperties(KeycloakSpringBootProperties.class)

此外,必须显式覆盖自定义键斗弹簧引导配置解析器 Bean。

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

推荐