Skip to content

Commit ac73766

Browse files
nosansnicoll
authored andcommitted
Do not auto-configure ViewResolver if spring-webmvc is absent
See gh-44259 Signed-off-by: Dmytro Nosan <[email protected]>
1 parent 6f05926 commit ac73766

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

+3-1
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.
@@ -56,6 +56,7 @@
5656
import org.springframework.util.MimeType;
5757
import org.springframework.util.unit.DataSize;
5858
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
59+
import org.springframework.web.servlet.view.AbstractCachingViewResolver;
5960

6061
/**
6162
* {@link EnableAutoConfiguration Auto-configuration} for Thymeleaf.
@@ -142,6 +143,7 @@ FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
142143
}
143144

144145
@Configuration(proxyBeanMethods = false)
146+
@ConditionalOnClass(AbstractCachingViewResolver.class)
145147
static class ThymeleafViewResolverConfiguration {
146148

147149
@Bean

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java

+9-1
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.
@@ -46,6 +46,7 @@
4646
import org.springframework.boot.test.system.CapturedOutput;
4747
import org.springframework.boot.test.system.OutputCaptureExtension;
4848
import org.springframework.boot.testsupport.BuildOutput;
49+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
4950
import org.springframework.boot.web.servlet.FilterRegistrationBean;
5051
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
5152
import org.springframework.context.annotation.Bean;
@@ -336,6 +337,13 @@ void cachingCanBeDisabled() {
336337
});
337338
}
338339

340+
@Test
341+
@ClassPathExclusions("spring-webmvc-*.jar")
342+
void missingAbstractCachingViewResolver() {
343+
this.contextRunner
344+
.run((context) -> assertThat(context).hasNotFailed().doesNotHaveBean("thymeleafViewResolver"));
345+
}
346+
339347
@Configuration(proxyBeanMethods = false)
340348
static class LayoutDialectConfiguration {
341349

0 commit comments

Comments
 (0)