Make WebProperties and WebMvcProperties optional in SwaggerConfig#3292
Open
seonwooj0810 wants to merge 1 commit into
Open
Make WebProperties and WebMvcProperties optional in SwaggerConfig#3292seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
springdoc#3288 The webmvc-ui starter's SwaggerWebMvcConfigurer bean directly injects WebProperties and WebMvcProperties since 2.8.15 (commit f09afb9, which introduced the WebJar resource handler refactor for springdoc#3146). Spring Boot's WebMvcAutoConfiguration normally provides both beans, but applications that disable that auto-configuration (e.g. plain Spring MVC apps that configure the web layer manually) suddenly fail to start with UnsatisfiedDependencyException when upgrading from 2.8.14 to 2.8.16. Switch the bean parameters to ObjectProvider so they are looked up lazily, falling back to default-constructed instances when the beans are absent. The default WebProperties enables resource mappings and the default WebMvcProperties exposes "/webjars/**" as the WebJar path pattern, matching the Spring Boot defaults that 2.8.14 effectively relied on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3288.
Summary
The webmvc-ui starter's
SwaggerWebMvcConfigurerbean has injectedWebPropertiesandWebMvcPropertiesdirectly since 2.8.15 (commit f09afb9, which introduced the WebJar resource-handler refactor for #3146). Spring Boot'sWebMvcAutoConfigurationnormally publishes both beans, but applications that intentionally disable that auto-configuration (for example a plain Spring MVC app that configures the web layer manually) now fail to start with anUnsatisfiedDependencyExceptionfor theswaggerWebMvcConfigurerbean — exactly the upgrade regression from 2.8.14 to 2.8.16 reported in #3288.Change
SwaggerConfig.swaggerWebMvcConfigurer(...)now declares the two property beans asObjectProvider<WebProperties>/ObjectProvider<WebMvcProperties>and falls back to default-constructed instances when the beans are absent:WebProperties::new—addMappingsdefaults totrue, matching the path thatAbstractSwaggerConfigurer.getSwaggerWebjarHandlerConfigs()takes when no resource bean exists.WebMvcProperties::new—webjarsPathPatterndefaults to/webjars/**, which is what Spring Boot's autoconfigured bean exposes and whatSwaggerWebMvcConfigurer.getWebjarsPathPattern()returned implicitly in 2.8.14.Apps that do have Spring Boot autoconfiguration pick up the autoconfigured beans through the
ObjectProvider, so existing behaviour is unchanged.Test plan
mvn -B -f springdoc-openapi-starter-webmvc-ui/pom.xml test—Tests run: 75, Failures: 0, Errors: 0, Skipped: 0onmain-equivalent baseline and unchanged after the fix.I did not add a dedicated regression test: the existing module relies on
@SpringBootTestwith@SpringBootApplicationtest apps, so a test that simulates the "no Spring Boot autoconfiguration" scenario would need a different harness (WebApplicationContextRunneror@SpringBootApplication(exclude = WebMvcAutoConfiguration.class)) than anything currently in this module. Happy to add one in the style maintainers prefer if useful.