我使用此示例: https://github.com/foo4u/keycloak-spring-demo
我的WEB-INF文件夹中有keycloak.json文件,但是当我运行我的应用程序时,我得到了这个例外:
java.lang.RuntimeException: Must set 'realm' in config
此例外的完整堆栈:
java.lang.RuntimeException: Must set 'realm' in config
at org.keycloak.adapters.KeycloakDeploymentBuilder.internalBuild(KeycloakDeploymentBuilder.java:53) ~[keycloak-adapter-core-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.KeycloakDeploymentBuilder.build(KeycloakDeploymentBuilder.java:152) ~[keycloak-adapter-core-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver.resolve(KeycloakSpringBootConfigResolver.java:37) ~[keycloak-spring-boot-adapter-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.AdapterDeploymentContext.resolveDeployment(AdapterDeploymentContext.java:88) ~[keycloak-adapter-core-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.PreAuthActionsHandler.preflightCors(PreAuthActionsHandler.java:107) ~[keycloak-adapter-core-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.PreAuthActionsHandler.handleRequest(PreAuthActionsHandler.java:79) ~[keycloak-adapter-core-2.4.0.Final.jar:2.4.0.Final]
at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:183) ~[keycloak-tomcat-core-adapter-2.4.0.Final.jar:2.4.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.5.jar:8.5.5]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.5.jar:8.5.5]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
这段代码只是Spring boot和Keycloak之间集成的一个例子。
你能告诉我我做错了什么吗?
感谢您的回答和时间。
答案 0 :(得分:1)
尽管这是一个很好且有效的例子,可以追溯到2015年。我相信它使用的是完全过时的Keycloak 1.2.0。 Spring here有一组示例。他们中的大多数都是最新的变化。
我建议您查看这些示例并阅读docs。
答案 1 :(得分:0)
如果您使用带有spring boot 2或spring boot 1.5的keycloak适配器,则必须在application.properties或application.yaml文件中提及以下属性
keycloak.auth-server-url=http://localhost:8180/auth
keycloak.realm=abc
keycloak.resource=movie-app
keycloak.public-client=false
keycloak.principal-attribute=preferred_username
如果仍然出现错误,请发布错误,我将分享代码:)