27

I'm trying to run example app from:

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
Raedwald
  • 46,613
  • 43
  • 151
  • 237
Krzysztof Tkacz
  • 488
  • 2
  • 5
  • 15
  • 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. [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. – Jonathan Crowe Sep 04 '19 at 16:30

3 Answers3

42

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();
    }
}
Thomas Vitale
  • 1,588
  • 10
  • 13
  • 1
    This worked for me. Digging in to what's happening here: check that your `keycloak.*` properties in application.properties / application.yaml are set up correctly. See the Keycloak quickstart examples for how to do this. – Mark Oct 07 '19 at 13:41
  • 1
    Thank you Tomas for your help! You saved a lot of my time :) Solution with declaring bean `KeycloakSpringBootConfigResolver` in separate configuration class works perfectly for me! – sobczak.dev Jan 17 '20 at 19:10
  • 1
    Side note: If you still want to have all keycloak configuration in one file then you can make the separate resolver configuration a static inner class. This inner class is also picked up by spring. – Steffen Harbich Feb 08 '20 at 08:25
  • 1
    The "LATEST UPDATE" works fine with Keycloak v8.0.2 – Avec Feb 15 '20 at 01:16
  • I would suggest declaring KeycloakSpringBootConfigResolver in a configuration class annotated with @KeycloakConfiguration along with all other Keycloak related beans – Andrey M. Stepanov Jun 06 '22 at 19:27
1

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);
}
Tamim
  • 365
  • 3
  • 11
1

I could solve this problem by adding some annotations in the KeycloakConfig class declaration:

@EnableWebSecurity
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class,
               excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, 
               pattern = "org.keycloak.adapters.springsecurity.management.HttpSessionManager"))
public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter 
{
}