Skip to content

Commit c219f5e

Browse files
eddumelendezwilkinsona
authored andcommitted
Don't create ApplicationContextHeaderFilter when header is disabled
See gh-4320 Closes gh-4454
1 parent b02cdc7 commit c219f5e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
4343
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
4444
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
45+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4546
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
4647
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
4748
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
@@ -87,6 +88,7 @@
8788
* @author Christian Dupuis
8889
* @author Andy Wilkinson
8990
* @author Johannes Edmeier
91+
* @author Eddú Meléndez
9092
*/
9193
@Configuration
9294
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
@@ -198,6 +200,7 @@ public Object getProperty(String name) {
198200
// Put Servlets and Filters in their own nested class so they don't force early
199201
// instantiation of ManagementServerProperties.
200202
@Configuration
203+
@ConditionalOnProperty(prefix = "management", name = "addApplicationContextHeader", matchIfMissing = true, havingValue = "true")
201204
protected static class ApplicationContextFilterConfiguration {
202205

203206
@Bean

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
* @author Phillip Webb
9999
* @author Greg Turnquist
100100
* @author Andy Wilkinson
101+
* @author Eddú Meléndez
101102
*/
102103
public class EndpointWebMvcAutoConfigurationTests {
103104

@@ -136,6 +137,7 @@ public void onSamePort() throws Exception {
136137
assertContent("/controller", ports.get().management, null);
137138
assertContent("/endpoint", ports.get().management, null);
138139
assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
140+
assertTrue(this.applicationContext.containsBean("applicationContextIdFilter"));
139141
this.applicationContext.close();
140142
assertAllClosed();
141143
}
@@ -149,6 +151,7 @@ public void onSamePortWithoutHeader() throws Exception {
149151
EndpointWebMvcAutoConfiguration.class);
150152
this.applicationContext.refresh();
151153
assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
154+
assertFalse(this.applicationContext.containsBean("applicationContextIdFilter"));
152155
this.applicationContext.close();
153156
assertAllClosed();
154157
}

0 commit comments

Comments
 (0)