From b402f00c779f724a48090b01e69b9c90e6053d6b Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 24 Nov 2022 22:31:49 +0100 Subject: [PATCH] GH-77 - Upgrade to Spring Boot 3.0. Adapt to API changes in Micrometer and Spring Boot's test context loader API now exposing a checked ContextLoadException to signal failures during ApplicationContext bootstraps. --- pom.xml | 2 +- .../observability/ModuleEntryInterceptor.java | 11 +++++------ .../springframework/modulith/test/TestUtils.java | 16 +++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 290cb172..40662a84 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ UTF-8 UTF-8 0.0.4-SNAPSHOT - 3.0.0-RC1 + 3.0.0 diff --git a/spring-modulith-observability/src/main/java/org/springframework/modulith/observability/ModuleEntryInterceptor.java b/spring-modulith-observability/src/main/java/org/springframework/modulith/observability/ModuleEntryInterceptor.java index 9b2216a1..45764898 100644 --- a/spring-modulith-observability/src/main/java/org/springframework/modulith/observability/ModuleEntryInterceptor.java +++ b/spring-modulith-observability/src/main/java/org/springframework/modulith/observability/ModuleEntryInterceptor.java @@ -15,7 +15,7 @@ */ package org.springframework.modulith.observability; -import io.micrometer.tracing.BaggageInScope; +import io.micrometer.tracing.Baggage; import io.micrometer.tracing.Span; import io.micrometer.tracing.Tracer; import io.micrometer.tracing.Tracer.SpanInScope; @@ -59,7 +59,7 @@ class ModuleEntryInterceptor implements MethodInterceptor { if (currentSpan != null) { - BaggageInScope currentBaggage = tracer.getBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY); + Baggage currentBaggage = tracer.getBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY); if (currentBaggage != null && moduleName.equals(currentBaggage.get())) { return invocation.proceed(); @@ -76,10 +76,9 @@ class ModuleEntryInterceptor implements MethodInterceptor { .tag(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName) .start(); - try ( - SpanInScope ws = tracer.withSpan(span); // - BaggageInScope baggage = tracer.createBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName); // - ) { + tracer.createBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName); + + try (SpanInScope ws = tracer.withSpan(span)) { return invocation.proceed(); diff --git a/spring-modulith-test/src/main/java/org/springframework/modulith/test/TestUtils.java b/spring-modulith-test/src/main/java/org/springframework/modulith/test/TestUtils.java index 5c117bc3..f82a7a75 100644 --- a/spring-modulith-test/src/main/java/org/springframework/modulith/test/TestUtils.java +++ b/spring-modulith-test/src/main/java/org/springframework/modulith/test/TestUtils.java @@ -25,6 +25,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.CacheAwareContextLoaderDelegate; +import org.springframework.test.context.ContextLoadException; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate; import org.springframework.test.context.support.DefaultBootstrapContext; @@ -52,13 +53,10 @@ public class TestUtils { return (ConfigurableApplicationContext) loader.loadContext(configuration); - } catch (Exception e) { - - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - - throw new RuntimeException(e); + } catch (ContextLoadException o_O) { + throw asRuntimeException(o_O.getCause()); + } catch (Exception o_O) { + throw asRuntimeException(o_O); } }); @@ -70,4 +68,8 @@ public class TestUtils { }); }); } + + private static RuntimeException asRuntimeException(Throwable o_O) { + return o_O instanceof RuntimeException ? (RuntimeException) o_O : new RuntimeException(o_O); + } }