当前位置: 首页 > 知识库问答 >
问题:

Spring-boot和Keycloak集成

许典
2023-03-14

我使用的是spring boot 2.1.7版本和keycloak-spring-boot-2-starter:4.0.0.final版本。这个keycloak-spring-boot-2-starter自动下载所需的keycloak适配器依赖项,对应于4.0.0..keycloak适配器依赖项的最终版本。现在,当我调用受keycloak保护的资源(rest api需要由keycloak服务器授权)时,我得到了以下错误:-

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”这样的属性,这就是为什么应用程序抛出“uncrectioned field”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等。

因此,我考虑使用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.

我使用以下版本:-oracle JDK-1.8spring-boot-2.1.7。release spring-cloud-dependencies:greenwich.sr2keycloak-7.0.0

谢谢。

共有1个答案

胡嘉歆
2023-03-14

我认为问题出在依赖项声明上,正如您在keycloak文档中看到的,您使用的liobrary是org.keycloak:keyCloak-spring-boot-starter。这个包包括使用keycloak所需的所有内容,还包括授权令牌所需的keycloak-authz-client。如果包含此库,您将删除上面指定的所有dependecies:

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项目中使用PowerMockito,但遇到了一个奇怪的问题。我正在使用PowerMockito模拟第三方库中的许多静态方法。 我的测试类遵循这个模式, 抽象测试类, 这很好,我可以模拟静态方法e.t.c,但当我引入第二个测试类时,我得到了以下错误:, 我的测试配置类如下所示,它加载了一个嵌入式Cassandra, 对我来说,它看起来像是试图添加一个已经存在的。有人

  • 我尝试用Spring Boot amd配置Key斗篷,我想使用自定义Key斗篷登录页面来获取访问令牌。然后我想把这个令牌传递给我的微服务中的restendpoint。我的Spring应用程序正在端口8081上运行。我在KeyClope管理控制台中设置有效重定向为。现在,在将登录jsessionid添加到url后的重定向过程中(看起来是这样的),我遇到异常: 从Spring Security配置它被

  • 谁能告诉我如何迁移keycloak和spring security。我已经遵循了http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#spring-security-adapter中步骤。但它很管用。我需要编写自己的提供程序吗? 我的原始spring-security.xml 我们很抱歉... 无效参数:re

  • 我尝试使用Spring集成HTTP开发SpringBoot Rest服务器- 我有一个控制器,用“@Controller”和“@RequestMapping”注释,并尝试创建以下流: 获取请求"/"- 但它不起作用。 我的集成Xml: 错误是: 但在我看来,控制器应该是通过Request Map注释的订阅者... 我上传了一个示例github项目:https://github.com/marcel

  • 本文向大家介绍如何集成 Spring Boot 和 ActiveMQ?相关面试题,主要包含被问及如何集成 Spring Boot 和 ActiveMQ?时的应答技巧和注意事项,需要的朋友参考一下 对于集成 Spring Boot 和 ActiveMQ,我们使用 spring-boot-starter-activemq 依赖关系。 它只需要很少的配置,并且不需要样板代码。

  • 我试图在Angular 9中构建前端应用程序,在spring boot中构建后端应用程序。 使用KeyClope对用户进行身份验证和授权。 我在Key斗篷上创建了两个客户端,一个前端是公共访问类型,一个后端是仅承载的。 angular应用程序是使用本教程配置的https://www.npmjs.com/package/keycloak-angular spring boot应用程序配置了此应用程序