Skip to content

Make WebProperties and WebMvcProperties optional in SwaggerConfig#3292

Open
seonwooj0810 wants to merge 1 commit into
springdoc:mainfrom
seonwooj0810:fix/issue-3288-webproperties-optional
Open

Make WebProperties and WebMvcProperties optional in SwaggerConfig#3292
seonwooj0810 wants to merge 1 commit into
springdoc:mainfrom
seonwooj0810:fix/issue-3288-webproperties-optional

Conversation

@seonwooj0810
Copy link
Copy Markdown

Fixes #3288.

Summary

The webmvc-ui starter's SwaggerWebMvcConfigurer bean has injected WebProperties and WebMvcProperties directly since 2.8.15 (commit f09afb9, which introduced the WebJar resource-handler refactor for #3146). Spring Boot's WebMvcAutoConfiguration normally 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 an UnsatisfiedDependencyException for the swaggerWebMvcConfigurer bean — exactly the upgrade regression from 2.8.14 to 2.8.16 reported in #3288.

Change

SwaggerConfig.swaggerWebMvcConfigurer(...) now declares the two property beans as ObjectProvider<WebProperties> / ObjectProvider<WebMvcProperties> and falls back to default-constructed instances when the beans are absent:

  • WebProperties::newaddMappings defaults to true, matching the path that AbstractSwaggerConfigurer.getSwaggerWebjarHandlerConfigs() takes when no resource bean exists.
  • WebMvcProperties::newwebjarsPathPattern defaults to /webjars/**, which is what Spring Boot's autoconfigured bean exposes and what SwaggerWebMvcConfigurer.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 testTests run: 75, Failures: 0, Errors: 0, Skipped: 0 on main-equivalent baseline and unchanged after the fix.

I did not add a dedicated regression test: the existing module relies on @SpringBootTest with @SpringBootApplication test apps, so a test that simulates the "no Spring Boot autoconfiguration" scenario would need a different harness (WebApplicationContextRunner or @SpringBootApplication(exclude = WebMvcAutoConfiguration.class)) than anything currently in this module. Happy to add one in the style maintainers prefer if useful.

 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade starter-webmvc-ui to 2.8.16 causes startup failure for Spring Boot 3.5 apps without WebProperties/WebMvcProperties

1 participant