Skip to content

Commit d9c5431

Browse files
committed
Merge pull request #44259 from nosan
* pr/44259: Polish "Do not auto-configure ViewResolver if spring-webmvc is absent" Do not auto-configure ViewResolver if spring-webmvc is absent Closes gh-44259
2 parents 6f05926 + 6aa0055 commit d9c5431

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-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

+8-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.
@@ -60,6 +60,7 @@
6060
import org.springframework.web.servlet.ViewResolver;
6161
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
6262
import org.springframework.web.servlet.support.RequestContext;
63+
import org.springframework.web.servlet.view.AbstractCachingViewResolver;
6364

6465
import static org.assertj.core.api.Assertions.assertThat;
6566

@@ -336,6 +337,12 @@ void cachingCanBeDisabled() {
336337
});
337338
}
338339

340+
@Test
341+
void missingAbstractCachingViewResolver() {
342+
this.contextRunner.withClassLoader(new FilteredClassLoader(AbstractCachingViewResolver.class))
343+
.run((context) -> assertThat(context).hasNotFailed().doesNotHaveBean("thymeleafViewResolver"));
344+
}
345+
339346
@Configuration(proxyBeanMethods = false)
340347
static class LayoutDialectConfiguration {
341348

0 commit comments

Comments
 (0)