-
Notifications
You must be signed in to change notification settings - Fork 40.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring Thymeleaf configuration for reactive support #8124
Comments
@bclozel I just want to double check if |
For now, we have no use case for creating a |
Oh right, they're different types. Ignore me. |
Thymeleaf 3.0 implements the Spring 5.0 view infrastructure for WebMVC and the new WebFlux framework. This commit adds auto-configuration for the WebFlux support. In that process, the configuration property for `spring.thymeleaf` has been changed to add `spring.thymeleaf.servlet` and `spring.thymeleaf.reactive` for MVC/WebFlux specific properties. Now that the `spring-boot-starter-thymeleaf` does not only support Spring MVC, the transitive dependency on `spring-boot-starter-web` is removed from it. Fixes spring-projectsgh-8124
This is awesome, thank you so much. There's just a small thing I think could be improved (related to media types), but I think that should go in a new ticket. I've now successfully applied auto-configuration based on
Thanks to this new support I've been able to remove almost all bean configuration for Thymeleaf and view resolution (except in one of the apps which actually requires two different |
This commit adds new reference documentation sections about WebFlux support in Spring Boot: * Support for multiple HTTP servers (gh-8403) * `CodecCustomizer` and JSON codecs (gh-8897, gh-9166) * `WebClient.Builder` auto-configuration (gh-9522) * Tests with `@WebFluxTest` (gh-8401) * `WebTestClient` auto-configuration (gh-8399) * Support for Thymeleafi and Mustache templating (gh-8124, gh-8648) * Choose another HTTP server with WebFlux (closes gh-9690)
I've been thinking about how Spring Boot could provide autoconfiguration for the new Thymeleaf integration with Spring Web Reactive and, though the view resolver and template engine in themselves present no issues (see my attempt), perhaps the current mechanism for Thymeleaf configuration via the
ThymeleafProperties
class (which matchesspring.thymeleaf.*
properties) might benefit from some refactoring.The issue comes from the fact that the
ThymeleafViewResolver
(for Spring Web MVC) and theThymeleafReactiveViewResolver
(for Spring Web Reactive) have different needs, so there are properties in the currentspring.thymeleaf
configuration namespace that wouldn't be used by the reactive side, and vice-versa. But there is still a good amount of properties that would be used in both scenarios, so having some kind of common configuration trunk still looks interesting.The following properties make sense for both MVC and Reactive (with the same default values):
spring.thymeleaf.checkTemplate
spring.thymeleaf.checkTemplateLocation
spring.thymeleaf.prefix
spring.thymeleaf.suffix
spring.thymeleaf.mode
spring.thymeleaf.cache
spring.thymeleaf.templateResolverOrder
spring.thymeleaf.viewNames
spring.thymeleaf.excludedViewNames
spring.thymeleaf.enabled
The following existing properties are actually MVC-only:
spring.thymeleaf.encoding
spring.thymeleaf.contentType
The following properties would be needed by the Thymeleaf Reactive infrastructure:
defaultCharset
(type:Charset
)supportedMediaTypes
(type:List<MediaType>
)responseMaxChunkSizeBytes
(type:int
)Note how most of the changes in requirements are due to the different way that response content types are managed in the MVC and the Reactive sides. Actually, both the
defaultCharset
and thesupportedMediaTypes
properties needed byThymeleafReactiveViewResolver
are in fact inherited fromorg.springframework.web.reactive.result.view.ViewResolverSupport
, so other view resolvers available for the reactive framework might also be affected by this.The new
responseMaxChunkSizeBytes
property is only needed for the reactive side because it is meant to be used for specifying the maximum size of theDataBuffer
objects generated by Thymeleaf in theFlux<DataBuffer>
returned to the server's output channels for template processing.As for how to refactor this, the first suggestion that comes off the top of my head would be to take the following steps:
ThymeleafProperties
class as only source of thymeleaf configuration properties.spring.thymeleaf.encoding
andspring.thymeleaf.contentType
.spring.thymeleaf.servlet.encoding
andspring.thymeleaf.servlet.contentType
replacing the deprecated ones. Or perhaps.mvc.
instead of.servlet.
, or any other name.spring.thymeleaf.reactive.defaultCharset
,spring.thymeleaf.reactive.mediaTypes
andspring.thymeleaf.reactive.responseMaxChunkSizeBytes
. Not sure about how to handle the multi-valued one though.spring.thymeleaf.reactive.*
properties and let the Thymeleaf+Reactive autoconfiguration ignore thespring.thymeleaf.servlet.*
ones.Anyway of course, you know much better the whole set of implications of a refactoring like this, and may be able to find a better approach.
BTW once the new configuration bits are available I'd be happy to contribute the bean autoconfiguration. Or you can just take the code I linked above, adjust it to your taste, and add the new properties.
The text was updated successfully, but these errors were encountered: