[spring-projects/spring-boot]@SpringBootTest 在 2.1.0.M4 中失败,并出现“logging.level”绑定错误

2024-04-20 883 views
0

将 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

回答

8

似乎当@TestPropertySource向这些测试添加 a 并添加虚拟日志记录属性时logging.level.some.logger.name=INFO,这个问题就消失了。

3

您能否提供一个小样本(我们可以解压缩或git clone)来重现您所描述的行为?我们有大量的测试和示例,它们@SpringBootTest在未配置日志记录级别的情况下使用,不会以您所描述的方式失败,因此我怀疑可能还有更多内容。

9

我正在开发一个项目,试图将复杂的项目简化为可以共享的简单项目。我开始怀疑这是否与包含的依赖项之一有关。

1

创建了一个简单的项目,除了启动一个简单的测试之外什么也不做,我可以得到错误。

0

@blake-bauman 这个示例项目适用于我,并且没有参考logging.level(它也相当复杂,因此您可能需要减少依赖项)。

8

@snicoll 对。问题是我在没有定义的情况下得到了上述错误logging.level。就好像依赖项加上环境的某种组合导致logging.level被初始化为空字符串而不是 null。这反过来会导致字符串无法转换为映射的错误。虽然某些环境似乎可以工作,但在 Jenkins 中构建却 100% 失败。

解决问题的方法:

  • 使用类路径资源定义@TestPropertySource,该资源定义随机记录器的logging.level。
  • 使用文件资源定义 a @TestPropertySource(即使未定义logging.level)

这很奇怪。我将进一步减少依赖关系,看看是否可以找出罪魁祸首。我可以设置任何选项来帮助我找到问题吗?

8

我猜想 Jenkins 上的某些东西正在设置带有字符串值的logging.level属性。例如,以下操作将失败:

LOGGING_LEVEL=boom java -jar target/demo-0.0.1-SNAPSHOT.jar
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:250) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:226) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:210) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:166) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.setLogLevels(LoggingApplicationListener.java:307) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeFinalLoggingLevels(LoggingApplicationListener.java:290) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:238) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:364) [spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) [spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
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.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter$CompositeConversionService.convert(BindConverter.java:162) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:96) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:88) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.MapBinder.bindAggregate(MapBinder.java:67) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.AggregateBinder.bind(AggregateBinder.java:58) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.lambda$bindAggregate$2(Binder.java:305) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:441) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder$Context.access$100(Binder.java:381) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bindAggregate(Binder.java:304) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:262) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:221) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
    ... 26 common frames omitted

本例中的应用程序是一个准系统的 Spring Boot 2.0.5 应用程序,spring-boot-starter仅依赖其他内容。

7

我明白了,我正在与 Jenkins 团队一起追踪这个问题,看看是否设置了任何奇怪的属性或环境变量。

然而,当降级到 Spring Boot 2.0.5(以及 Spring 5.0.8)时,这个问题就消失了。

我已将测试项目中的依赖关系减少到最低限度。

0

然而,当降级到 Spring Boot 2.0.5(以及 Spring 5.0.8)时,这个问题就消失了。

这太令人惊讶了。我看到 2.0.5 失败,如上面的堆栈跟踪所示。 2.0.4 也失败了:

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:250) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:226) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:210) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:166) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.setLogLevels(LoggingApplicationListener.java:307) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeFinalLoggingLevels(LoggingApplicationListener.java:290) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:238) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:361) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at com.example.loggingleveltest.DemoApplication.main(DemoApplication.java:10) [classes!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [logging-level-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [logging-level-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [logging-level-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [logging-level-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
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.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter$CompositeConversionService.convert(BindConverter.java:162) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:96) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:88) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.MapBinder.bindAggregate(MapBinder.java:67) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.AggregateBinder.bind(AggregateBinder.java:58) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.lambda$bindAggregate$2(Binder.java:305) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:441) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder$Context.access$100(Binder.java:381) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bindAggregate(Binder.java:304) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:262) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:221) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
    ... 26 common frames omitted

如果您没有看到 2.0.4 出现故障,但确实看到 2.1.0.M4 出现故障,那么问题的原因比您当前描述的要多。如果您希望我们在这方面取得更多进展,我们将需要一个适用于 2.0.4 且适用于 2.1.0.M4 的示例。

0

你的堆栈跟踪来自哪里?这不是我贴的我知道因为做了一些我们不做的事情而导致了失败,但这并不意味着这与我的问题的原因相同。这当然并不意味着我没有看到我所看到的。

使用我提供的示例,可以成功:

        <version.spring>5.0.8.RELEASE</version.spring>
        <version.spring.boot>2.0.5.RELEASE</version.spring.boot>

这失败了:

        <version.spring>5.1.0.RELEASE</version.spring>
        <version.spring.boot>2.1.0.M4</version.spring.boot>

我知道你无法重新创建这个。这可能比我描述的更多,但从字面上看,上述更改是我需要进行的触发失败的唯一更改。我对 Spring Boot 的内部“魔力”了解不够,不知道从哪里开始寻找。我当然不知道这些版本之间发生了什么变化,以了解可能的环境影响触发了新版本中的失败,但没有触发前一个版本中的失败。该作业可能配置不正确并且需要修复,但是上面的版本控制是成功和不成功构建之间的唯一变化。

由于此故障发生得太早并且涉及初始化日志记录,因此添加日志记录语句已被证明是无效的。鉴于版本是唯一的更改,我正在寻找在哪里查找的想法,以便我可以帮助追踪触发问题的具体更改。

0

我并不是说你没有看到你认为你看到的东西。我所说的只是我认为这比目前描述的更多。具体来说,我目前最好的猜测是您logger.level在失败的环境中有一个名为 set 的属性。但是,如果这么简单,您会看到 Boot 2.0.4、2.0.5 和 2.1.0.M4 失败,因为如我上面评论中的堆栈跟踪所示,它们在以下情况下的行为方式相同:logger.level已设置。

如果,当您重现问题时,您可以附加调试器,我会查看 inEnvironmentLoggingApplicationListener.setLogLevels(LoggingSystem, Environment)查看它包含哪些属性源以及每个源包含哪些值。

1

好,谢谢。会做。

5

如果您希望我们查看此问题,请提供所需的信息。如果在接下来的 7 天内未提供信息,此问题将被关闭。

4

到目前为止,我无法在可以附加调试器的环境中重新创建它。我将继续在这里寻找 Jenkins 的特别之处。

4

所以,不确定发生了什么变化,但我将测试项目更新到 Spring 5.1.1(从 5.1.0)和 SB 2.1.0.RC1(从 2.1.0.M4),问题得到解决。

我绝对无法解释。

7

我暂时关闭它,因为我们无法再重现它。

2

我也遇到过同样的问题,除了 Spring Boot 2.1.2(在应用程序启动时)。我使用 log4j2 starter 只是为了一些额外的上下文:如果我使用系统环境变量 LOGGING_LEVEL ,它会抛出上述错误。如果我将 log.level.[name] 添加到 application.properties,此错误就会消失,但我的 log4j2.xml 会被忽略。一旦我删除 LOGGING_LEVEL 作为环境变量,我就可以从属性中删除 log.level,并且 spring 日志记录将尊重我的 log4j2.xml。另外,根据文档,它说我可以使用 log4j2-spring.xml,但是,它似乎不再起作用。

5

如果我使用系统环境变量,LOGGING_LEVEL它会抛出上述错误

这是可以预料的,也是我怀疑导致上述问题的原因。

如果我添加log.level.[name]到此application.properties错误消失,但我的 log4j2.xml 被忽略

我猜你的意思是logging.level.[name]?添加这样的属性不应导致您的 log4j2.xml 被忽略。如果发生这种情况,则问题与此处报告的问题不同。如果您希望我们进行调查,请打开一个新问题,其中包含重现该问题的最小且完整的示例。它应该采用附加到问题的 zip 形式,或者是我们可以克隆的单独存储库。

0

是的。日志记录级别。[名称]。基本上,如果在 application.properties 中定义,例如logging.level.root,它将覆盖 log4j2.xml 中的 Root 条目。我关心的并不是真正尝试协调 application.properties 和 log4j2.xml 之间的属性,我只是没有在 Spring Boot 1.5 中看到这种行为,环境变量 LOGGING_LEVEL 会导致属性异常。看起来我刚刚错过了迁移指南中的配置部分。我的错误,感谢帮助(如果其他人有这个问题):https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0:LOGGING_LEVEL 翻译为 spring 的logging.level,需要日志记录.级别.[名称]。

3

我使用了这里解释的以下技巧。

有一个很好的小技巧可以触发上下文刷新 - 使用 org.springframework.cloud.context.refresh.ContextRefresher

https://stackoverflow.com/questions/24720330/reload-or-refresh-a-spring-application-context-inside-a-test-method

在最新的 Spring Boot 稳定版本 + Maven 存储库上可用的最新版本 org.springframework.cloud 上,当我使用

在org.springframework.cloud.context.refresh.ContextRefresher.refresh(ContextRefresher.java:83)

这是堆栈跟踪

org.springframework.boot.context.properties.bind.BindException:无法将 'logging.level' 下的属性绑定到 org.springframework.boot 处的 java.util.Map<java.lang.String, java.lang.String>。 context.properties.bind.Binder.handleBindError(Binder.java:363) 在 org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:323) 在 org.springframework.boot.context.properties。 bind.Binder.bind(Binder.java:308) 在 org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:238) 在 org.springframework.boot.context.properties.bind.Binder。绑定(Binder.java:199)在org.springframework.cloud.logging.LoggingRebinder.setLogLevels(LoggingRebinder.java:67)在org.springframework.cloud.logging.LoggingRebinder.onApplicationEvent(LoggingRebinder.java:63)在org.springframework .cloud.logging.LoggingRebinder.onApplicationEvent(LoggingRebinder.java:44) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java :169)在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)在org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:426)在org.springframework.context.support。 AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)在org.springframework.cloud.context.refresh.ContextRefresher.refreshEnvironment(ContextRefresher.java:92)在org.springframework.cloud.context.refresh.ContextRefresher.refresh(ContextRefresher.java: 83)

使用 yml 文件中相同的日志记录配置,正常的 Spring Boot 应用程序可以正常启动(这不是使用 cloud.context.refresh.ContextRefresher.refresh ),但在使用 cloud.context.refresh.ContextRefresher.refresh 的 JUnit 5 中会出现错误正在发生。

然后我尝试了另一个测试,其中我从 yml 文件中删除了所有与日志记录相关的配置,正常的 spring boot 应用程序继续启动,没有任何错误,而使用 cloud.context.refresh.ContextRefresher.refresh 的 JUnit 5 测试继续失败有同样的例外(即使所有与日志记录相关的配置都已从 yml 文件中删除)。