Example keycloak spring-boot app fails to find bean KeycloakSpringBootConfigResolver

后端 未结 2 843
北荒
北荒 2020-12-15 05:01

I\'m trying to run example app from:

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

I\'m getting error:

********         


        
相关标签:
2条回答
  • 2020-12-15 05:21

    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. The problem seems to be caused by the code delivered with this 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." (source: 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.

    @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. This option will fix issues with both Spring Boot and Spring Security.

    @Configuration
    public class KeycloakConfig {
    
        @Bean
        public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
            return new KeycloakSpringBootConfigResolver();
        }
    }
    
    0 讨论(0)
  • 2020-12-15 05:35

    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:

    @EnableConfigurationProperties(KeycloakSpringBootProperties.class)
    

    Furthermore the custom keycloak spring boot config resolver bean must be overriden explicitly.

    @Bean
    @Primary
    public KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties properties) {
          return new MyKeycloakSpringBootConfigResolver(properties);
    }
    
    0 讨论(0)
提交回复
热议问题