Skip to content

Commit 3ab2ce5

Browse files
committed
Merge branch '3.4.x'
Closes gh-45297
2 parents 67d23d5 + 38354c5 commit 3ab2ce5

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ public static final class JerseyWebApplicationInitializer implements WebApplicat
173173

174174
@Override
175175
public void onStartup(ServletContext servletContext) throws ServletException {
176-
// We need to switch *off* the Jersey WebApplicationInitializer because it
177-
// will try and register a ContextLoaderListener which we don't need
178-
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
176+
if (ClassUtils.isPresent("org.glassfish.jersey.server.spring.SpringWebApplicationInitializer",
177+
getClass().getClassLoader())) {
178+
// We need to switch *off* the Jersey WebApplicationInitializer because it
179+
// will try and register a ContextLoaderListener which we don't need
180+
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
181+
}
179182
}
180183

181184
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,18 +16,25 @@
1616

1717
package org.springframework.boot.autoconfigure.jersey;
1818

19+
import java.util.Collections;
20+
1921
import com.fasterxml.jackson.databind.ObjectMapper;
2022
import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector;
23+
import jakarta.servlet.ServletContext;
24+
import jakarta.servlet.ServletException;
2125
import org.glassfish.jersey.server.ResourceConfig;
2226
import org.junit.jupiter.api.Test;
2327

2428
import org.springframework.boot.autoconfigure.AutoConfigurations;
2529
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
30+
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration.JerseyWebApplicationInitializer;
2631
import org.springframework.boot.test.context.FilteredClassLoader;
2732
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
33+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
2834
import org.springframework.boot.web.servlet.FilterRegistrationBean;
2935
import org.springframework.context.annotation.Bean;
3036
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.mock.web.MockServletContext;
3138
import org.springframework.web.filter.RequestContextFilter;
3239

3340
import static org.assertj.core.api.Assertions.assertThat;
@@ -106,6 +113,22 @@ void whenJacksonJaxbModuleIsNotAvailableTheObjectMapperCustomizationBacksOff() {
106113
.stream()
107114
.filter(JakartaXmlBindAnnotationIntrospector.class::isInstance)).isEmpty();
108115
});
116+
117+
}
118+
119+
@Test
120+
void webApplicationIntializerDisablesJerseysWebApplicationInitializer() throws ServletException {
121+
ServletContext context = new MockServletContext();
122+
new JerseyWebApplicationInitializer().onStartup(context);
123+
assertThat(context.getInitParameter("contextConfigLocation")).isEqualTo("<NONE>");
124+
}
125+
126+
@Test
127+
@ClassPathExclusions("jersey-spring6-*.jar")
128+
void webApplicationInitializerHasNoEffectWhenJerseyIsAbsent() throws ServletException {
129+
ServletContext context = new MockServletContext();
130+
new JerseyWebApplicationInitializer().onStartup(context);
131+
assertThat(Collections.list(context.getInitParameterNames())).isEmpty();
109132
}
110133

111134
@Configuration(proxyBeanMethods = false)

0 commit comments

Comments
 (0)