diff --git a/CHANGELOG.md b/CHANGELOG.md index 788797d00a..2f0422b9fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Do not register `sentrySpringFilter` in ServletContext for Spring Boot ([#3027](https://github.com/getsentry/sentry-java/pull/3027)) + ## 6.33.0 ### Features diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringServletContainerInitializer.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringServletContainerInitializer.java index 21c9c92b12..9a71bc6910 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringServletContainerInitializer.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringServletContainerInitializer.java @@ -1,5 +1,7 @@ package io.sentry.spring.jakarta; +import static io.sentry.util.ClassLoaderUtils.classLoaderOrDefault; + import com.jakewharton.nopen.annotation.Open; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterRegistration; @@ -20,10 +22,17 @@ public class SentrySpringServletContainerInitializer implements ServletContainer @Override public void onStartup(final @Nullable Set> c, final @NotNull ServletContext ctx) throws ServletException { - final FilterRegistration.Dynamic dynamic = - ctx.addFilter("sentrySpringFilter", SentrySpringFilter.class); - if (dynamic != null) { - dynamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); + try { + Class.forName( + "org.springframework.boot.SpringApplication", + false, + classLoaderOrDefault(getClass().getClassLoader())); + } catch (ClassNotFoundException e) { + final FilterRegistration.Dynamic dynamic = + ctx.addFilter("sentrySpringFilter", SentrySpringFilter.class); + if (dynamic != null) { + dynamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); + } } } }