将 Spring 从 5.0.8.RELEASE 更新到 5.1.0.RELEASE 并将 Spring Boot 从 2.0.4.RELEASE 更新到 2.1.0.M4 后,带有注释的测试@SpringBootTest
失败,并出现logging.level
.错误是:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'logging.level' to java.util.Map<java.lang.String, java.lang.String>
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
在大多数测试中,logging.level
根本没有定义,但会出现此错误。在其他情况下,application.yml
类路径 ( ) 上有一个文件/src/main/resources/
,其中定义了以下内容:
logging:
level:
com.foo.bar: DEBUG
但它仍然失败。 logging.group
没有在任何地方定义。这些在 Spring 5.0.8 和 Spring Boot 2.0.4 上运行良好,但在更新到 5.1.0 和 2.1.0.M4 时失败。
完整的堆栈跟踪是:
org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'logging.level' to java.util.Map<java.lang.String, java.lang.String>
at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:249) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:225) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:209) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:165) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.logging.LoggingApplicationListener.setLogLevels(LoggingApplicationListener.java:328) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeFinalLoggingLevels(LoggingApplicationListener.java:309) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:257) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:219) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:192) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:371) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:197) [spring-cloud-context-2.1.0.M1.jar:2.1.0.M1]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104) [spring-cloud-context-2.1.0.M1.jar:2.1.0.M1]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70) [spring-cloud-context-2.1.0.M1.jar:2.1.0.M1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) [spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:371) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139) [spring-boot-test-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44) [spring-boot-test-autoconfigure-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:97) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.java:349) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.java:349) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) [?:?]
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) [?:?]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1492) [?:?]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) [?:?]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) [?:?]
at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312) [?:?]
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735) [?:?]
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734) [?:?]
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658) [?:?]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.java:348) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:270) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:259) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.java:263) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at java.util.Optional.orElseGet(Optional.java:358) [?:?]
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.java:262) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:82) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:59) [junit-jupiter-engine-5.3.0.jar:5.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:116) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:116) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:102) [junit-platform-engine-1.3.0.jar:1.3.0]
at java.util.ArrayList.forEach(ArrayList.java:1378) [?:?]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:127) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:107) [junit-platform-engine-1.3.0.jar:1.3.0]
at java.util.ArrayList.forEach(ArrayList.java:1378) [?:?]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:127) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:107) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:52) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) [junit-platform-engine-1.3.0.jar:1.3.0]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220) [junit-platform-launcher-1.3.0.jar:1.3.0]
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188) [junit-platform-launcher-1.3.0.jar:1.3.0]
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202) [junit-platform-launcher-1.3.0.jar:1.3.0]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181) [junit-platform-launcher-1.3.0.jar:1.3.0]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) [junit-platform-launcher-1.3.0.jar:1.3.0]
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:142) [surefire-junit-platform-2.22.0.jar:2.22.0]
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:117) [surefire-junit-platform-2.22.0.jar:2.22.0]
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:383) [surefire-booter-2.22.0.jar:2.22.0]
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:344) [surefire-booter-2.22.0.jar:2.22.0]
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125) [surefire-booter-2.22.0.jar:2.22.0]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:417) [surefire-booter-2.22.0.jar:2.22.0]
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.boot.context.properties.bind.BindConverter$CompositeConversionService.convert(BindConverter.java:179) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:98) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:90) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.MapBinder.bindAggregate(MapBinder.java:66) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.AggregateBinder.bind(AggregateBinder.java:58) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.lambda$bindAggregate$2(Binder.java:304) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:439) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder$Context.access$100(Binder.java:379) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bindAggregate(Binder.java:303) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:261) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:220) ~[spring-boot-2.1.0.M4.jar:2.1.0.M4]
... 86 more