我想为 Spring Boot 2.1.x 后端设置 Keycloak 适配器 (v7.0.0)。不知怎的,这并没有按预期工作,并且 mvn clean spring:boot-run
显示错误。
为了获得一个 Playground ,我克隆了这个工作 repo 。使用旧版本的 Keycloak 和 Spring Boot 成功构建后,我更改了依赖项(和版本)。
对于我包含的 POM:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>7.0.0</version>
</dependency>
和
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>7.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
并通过 application.yml
文件提供属性:
keycloak:
auth-server-url: http://127.0.0.1:8081/auth/
resource: persons-app
realm: PersonRealm
public-client: true
principal-attribute: preferred_username
下面是Keycloaks docs .
结果是一个错误,显示:
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.
这已经定义了。这就是问题所在。我不知道什么版本的Keycloak和Spring Boot一起工作是否有一定的限制。也许有人可以解释我在这里错过了什么或者要设置什么版本。谢谢!
最佳答案
这里也提出了同样的问题:Issues running example keycloak spring-boot app我将向您指出另一个问题,以获取有关该问题和临时解决方法的更多信息。
目前还没有最终的解决方案,这是 Keycloak Spring Boot Adapter 7.0.0 的问题。如果您使用以前版本的适配器 (6.0.1),那么即使 Keycloak 服务器运行版本 7.0.0,它也会正常工作(您只是无法获得新适配器中引入的新功能)。
关于java - 如何将 Keycloak 7 与 Spring Boot 2 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57790317/