无法使用 spring-security-oauth2 和 Tomcat 从 CF 解析 ClientId
ClientId can not be parsed from CF with spring-security-oauth2 and Tomcat
从 Spring boot 2.1.13 更新到最新的 2.2.5 后,我的一些 Tomcat 应用程序无法部署到 cloud foundry。
日志中的错误信息
2020-03-23T13:13:34.84-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.848 WARN 28 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.85-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.859 INFO 28 --- [ main] ConditionEvaluationReportLoggingListener :
2020-03-23T13:13:34.85-0400 [APP/PROC/WEB/0] OUT Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.865 ERROR 28 --- [ main] o.s.boot.SpringApplication : Application run failed
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:609)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:310)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.access0(ConfigurationClassParser.java:110)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports(ConfigurationClassParser.java:811)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at java.util.ArrayList.forEach(ArrayList.java:1257)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at com.kroger.cxp.app.PythonApplication.main(PythonApplication.java:11)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at java.lang.reflect.Method.invoke(Method.java:498)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:225)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:371)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:271)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT ... 30 common frames omitted
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'vcap.services.oauth.credentials.clientId' in value "${vcap.services.oauth.credentials.clientId}"
这只会在部署到 CF 时发生,并且只会在升级后发生。我确认属性中没有任何更改,用户提供的服务确实具有正确的值。
这是在 Spring 引导 2.2.5.RELEASE
中引入的 known issue。它将在 2.2.6.RELEASE
中修复,目前计划于 2020 年 3 月 26 日发布。现在您可以将 Spring 启动版本退回到 2.2.4.RELEASE
。
从 Spring boot 2.1.13 更新到最新的 2.2.5 后,我的一些 Tomcat 应用程序无法部署到 cloud foundry。
日志中的错误信息
2020-03-23T13:13:34.84-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.848 WARN 28 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.85-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.859 INFO 28 --- [ main] ConditionEvaluationReportLoggingListener :
2020-03-23T13:13:34.85-0400 [APP/PROC/WEB/0] OUT Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT 2020-03-23 17:13:34.865 ERROR 28 --- [ main] o.s.boot.SpringApplication : Application run failed
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:609)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:310)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.access0(ConfigurationClassParser.java:110)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports(ConfigurationClassParser.java:811)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at java.util.ArrayList.forEach(ArrayList.java:1257)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at com.kroger.cxp.app.PythonApplication.main(PythonApplication.java:11)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at java.lang.reflect.Method.invoke(Method.java:498)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$RequestScopedConfiguration
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:225)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:371)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:271)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT ... 30 common frames omitted
2020-03-23T13:13:34.86-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'vcap.services.oauth.credentials.clientId' in value "${vcap.services.oauth.credentials.clientId}"
这只会在部署到 CF 时发生,并且只会在升级后发生。我确认属性中没有任何更改,用户提供的服务确实具有正确的值。
这是在 Spring 引导 2.2.5.RELEASE
中引入的 known issue。它将在 2.2.6.RELEASE
中修复,目前计划于 2020 年 3 月 26 日发布。现在您可以将 Spring 启动版本退回到 2.2.4.RELEASE
。