示例 keycloak spring-boot app 找不到 bean KeycloakSpringBootConfigResolver
Example keycloak spring-boot app fails to find bean KeycloakSpringBootConfigResolver
我正在尝试 运行 示例应用来自:
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
我目前没有解决方案,但我可以看到几个月前在 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的作者是这样描述问题的:
"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."
(来源: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;
}
}
最新更新
一个更简单的解决问题的方法是在单独的配置class中声明一个KeycloakSpringBootConfigResolver
。此选项将解决 Spring 引导和 Spring 安全问题。
@Configuration
public class KeycloakConfig {
@Bean
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
}
对我有用。 keycloak spring 引导属性 class 必须手动启用,方法是像这样注释应用程序 class:
@EnableConfigurationProperties(KeycloakSpringBootProperties.class)
此外,自定义 keycloak spring 引导配置解析器 bean 必须明确覆盖。
@Bean
@Primary
public KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties properties) {
return new MyKeycloakSpringBootConfigResolver(properties);
}
我可以通过在 KeycloakConfig class 声明中添加一些注释来解决这个问题:
@EnableWebSecurity
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class,
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX,
pattern = "org.keycloak.adapters.springsecurity.management.HttpSessionManager"))
public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter
{
}
我正在尝试 运行 示例应用来自:
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
我目前没有解决方案,但我可以看到几个月前在 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的作者是这样描述问题的: "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." (来源: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;
}
}
最新更新
一个更简单的解决问题的方法是在单独的配置class中声明一个KeycloakSpringBootConfigResolver
。此选项将解决 Spring 引导和 Spring 安全问题。
@Configuration
public class KeycloakConfig {
@Bean
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
}
@EnableConfigurationProperties(KeycloakSpringBootProperties.class)
此外,自定义 keycloak spring 引导配置解析器 bean 必须明确覆盖。
@Bean
@Primary
public KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties properties) {
return new MyKeycloakSpringBootConfigResolver(properties);
}
我可以通过在 KeycloakConfig class 声明中添加一些注释来解决这个问题:
@EnableWebSecurity
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class,
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX,
pattern = "org.keycloak.adapters.springsecurity.management.HttpSessionManager"))
public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter
{
}