Spring-boot 和 Keycloak 集成
Posted
技术标签:
【中文标题】Spring-boot 和 Keycloak 集成【英文标题】:Spring-boot and Keycloak Integration 【发布时间】:2020-01-11 07:00:35 【问题描述】:我正在使用 spring boot 2.1.7 Release 和 keycloak-spring-boot-2-starter:4.0.0.Final 版本。 这个keycloak-spring-boot-2-starter会自动下载4.0.0对应的keycloak适配器依赖项。keycloak适配器依赖项的最终发布。 现在,当我调用 keycloak 保护资源(需要由 keycloak 服务器授权的其余 api)时,我收到以下错误:-
java.lang.RuntimeException: Could not obtain configuration from server [http://localhost:8180/auth/realms/mint/.well-known/uma2-configuration].
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:242) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.authorization.client.AuthzClient.create(AuthzClient.java:85) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.authorization.PolicyEnforcer.<init>(PolicyEnforcer.java:66) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.KeycloakDeploymentBuilder.internalBuild(KeycloakDeploymentBuilder.java:143) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.KeycloakDeploymentBuilder.build(KeycloakDeploymentBuilder.java:169) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver.resolve(KeycloakSpringBootConfigResolver.java:37) ~[keycloak-spring-boot-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.AdapterDeploymentContext.resolveDeployment(AdapterDeploymentContext.java:88) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.PreAuthActionsHandler.preflightCors(PreAuthActionsHandler.java:107) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.PreAuthActionsHandler.handleRequest(PreAuthActionsHandler.java:79) ~[keycloak-adapter-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:177) ~[spring-boot-container-bundle-4.0.0.Final.jar:4.0.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747) [tomcat-embed-core-9.0.19.jar:9.0.19]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.19.jar:9.0.19]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_221]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_221]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.19.jar:9.0.19]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_221]
Caused by: java.lang.RuntimeException: Error executing http method [RequestBuilder [method=GET, charset=UTF-8, version=null, uri=http://localhost:8180/auth/realms/mint/.well-known/uma2-configuration, headerGroup=null, entity=null, parameters=null, config=null]]. Response : [B@1aa5d283
at org.keycloak.authorization.client.util.HttpMethod.execute(HttpMethod.java:106) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.authorization.client.util.HttpMethodResponse$2.execute(HttpMethodResponse.java:50) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:240) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
... 22 common frames omitted
Caused by: java.lang.RuntimeException: Error parsing JSON response.
at org.keycloak.authorization.client.util.HttpMethodResponse$2$1.process(HttpMethodResponse.java:56) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.authorization.client.util.HttpMethod.execute(HttpMethod.java:102) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
... 24 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "introspection_endpoint" (class org.keycloak.authorization.client.representation.ServerConfiguration), not marked as ignorable (27 known properties: "end_session_endpoint", "check_session_iframe", "grant_types_supported", "scopes_supported", "claims_parameter_supported", "userinfo_signing_alg_values_supported", "subject_types_supported", "authorization_endpoint", "request_object_signing_alg_values_supported", "token_introspection_endpoint", "response_modes_supported", "jwks_uri", "claim_types_supported", "claims_supported", "request_parameter_supported", "response_types_supported", "token_endpoint_auth_methods_supported", "id_token_signing_alg_values_supported", "issuer", "policy_endpoint", "permission_endpoint", "request_uri_parameter_supported", "token_endpoint", "token_endpoint_auth_signing_alg_values_supported", "resource_registration_endpoint", "userinfo_endpoint", "registration_endpoint"])
at [Source: (byte[])""issuer":"http://localhost:8180/auth/realms/mint","authorization_endpoint":"http://localhost:8180/auth/realms/mint/protocol/openid-connect/auth","token_endpoint":"http://localhost:8180/auth/realms/mint/protocol/openid-connect/token","token_introspection_endpoint":"http://localhost:8180/auth/realms/mint/protocol/openid-connect/token/introspect","end_session_endpoint":"http://localhost:8180/auth/realms/mint/protocol/openid-connect/logout","jwks_uri":"http://localhost:8180/auth/realms/mint/protoco"[truncated 1119 bytes]; line: 1, column: 1539] (through reference chain: org.keycloak.authorization.client.representation.ServerConfiguration["introspection_endpoint"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:823) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1153) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1589) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1567) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013) ~[jackson-databind-2.9.8.jar:2.9.8]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3091) ~[jackson-databind-2.9.8.jar:2.9.8]
at org.keycloak.util.JsonSerialization.readValue(JsonSerialization.java:69) ~[keycloak-core-4.0.0.Final.jar:4.0.0.Final]
at org.keycloak.authorization.client.util.HttpMethodResponse$2$1.process(HttpMethodResponse.java:54) ~[keycloak-authz-client-4.0.0.Final.jar:4.0.0.Final]
... 25 common frames omitted
当我从 keycloak-authz-client-4.0.0.Final.jar jar 反编译 ServerConfiguration.class 时,我可以看到没有“introspection_endpoint”这样的属性,这就是应用程序抛出错误的原因'无法识别的字段“introspection_endpoint”'。
当我查看 keycloak-authz-client 的相对较低版本,即 keycloak-authz-client-3.3.0.Final.jar 时,我可以看到存在“introspection_endpoint”属性。因此,该属性似乎在较高版本中的某处被删除,例如 keycloak-authz-client-4.0.0.Final.jar、keycloak-authz-client-4.0.0.Beta2.jar .etc。
所以我想到了使用 keycloak-spring-boot-starter 而不是 keycloak-spring-boot-2- 并注入相应版本的 keycloak 适配器 BOM。我手动包含了以下依赖项:-
compile "org.keycloak:keycloak-spring-boot-starter:3.3.0.Final"
compile "org.keycloak:keycloak-spring-boot-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-authz-client:3.3.0.Final"
compile "org.keycloak:keycloak-spring-security-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-spring-boot-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-core:3.3.0.Final"
compile "org.keycloak:keycloak-adapter-spi:3.3.0.Final"
compile "org.keycloak:keycloak-adapter-core:3.3.0.Final"
compile "org.keycloak:keycloak-common:3.3.0.Final"
但是现在当我尝试运行 spring boot 应用程序时,它退出并出现以下错误:-
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.audit.AuditAutoConfiguration$AuditEventRepositoryConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:447) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:128) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at com.azilen.micro.api.gateway.MintApiGateway.main(MintApiGateway.java:19) [main/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.keycloak.adapters.springboot.KeycloakAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:507) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:404) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:389) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:447) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_221]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:738) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:679) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:647) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1518) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1023) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:189) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:156) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanType(BeanTypeRegistry.java:149) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:137) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_221]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:132) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:96) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:269) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:262) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:251) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:171) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:145) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizer
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_221]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_221]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_221]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:489) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_221]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_221]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_221]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_221]
... 43 common frames omitted
2019-09-09 18:13:24.553 WARN 28792 --- [ main] o.s.boot.SpringApplication : Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [org.keycloak.adapters.springboot.KeycloakAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:507) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:404) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:389) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:447) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_221]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:738) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:679) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:647) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1518) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:511) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:481) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:602) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:594) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1226) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:865) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:853) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:840) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:791) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at com.azilen.micro.api.gateway.MintApiGateway.main(MintApiGateway.java:19) [main/:na]
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizer
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_221]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_221]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_221]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:489) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_221]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_221]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_221]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_221]
... 25 common frames omitted
Note:- It appears that the spring boot version and keycloak adapter are not compatible to each other.
Has anyone faced this issue before?
One solution/workaround that I can think off is to edit the ServerConfiguration.class of keycloak-authz-client-4.0.0.Final.jar and add the "introspection_endpoint".
Request you to please advise if anyone has faced a similar issue.
我正在使用以下版本:- 甲骨文 jdk - 1.8 春季启动 - 2.1.7.RELEASE spring-cloud-dependencies:Greenwich.SR2 钥匙斗篷 - 7.0.0
谢谢
【问题讨论】:
你为什么要使用这么旧的库?查看docs 获取最新版本。 【参考方案1】:我认为您的问题出在依赖项声明中,正如您在keycloak documentation 中看到的那样,您使用的图书馆是 org.keycloak:keycloak-spring-boot-starter。该软件包包括您使用 keycloak 所需的所有内容,还包括授权令牌所需的 keycloak-authz-client。如果您包含此库,您将删除您在上面的所有依赖项:
compile "org.keycloak:keycloak-spring-boot-starter:3.3.0.Final"
compile "org.keycloak:keycloak-spring-boot-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-authz-client:3.3.0.Final"
compile "org.keycloak:keycloak-spring-security-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-spring-boot-adapter:3.3.0.Final"
compile "org.keycloak:keycloak-core:3.3.0.Final"
compile "org.keycloak:keycloak-adapter-spi:3.3.0.Final"
compile "org.keycloak:keycloak-adapter-core:3.3.0.Final"
compile "org.keycloak:keycloak-common:3.3.0.Final"
【讨论】:
以上是关于Spring-boot 和 Keycloak 集成的主要内容,如果未能解决你的问题,请参考以下文章
403 spring-boot-2-keycloak-适配器
在 spring-boot 中禁用特定 url 的 Keycloak 身份验证
示例 keycloak spring-boot 应用程序无法找到 bean KeycloakSpringBootConfigResolver
如何在 spring-boot 应用程序中配置多个 Keycloak sso 客户端?