Skip to content

Improve diagnostics for missing ServletContext - #51425

Open
xoruddl wants to merge 2 commits into
spring-projects:mainfrom
xoruddl:issue-16936-enable-webmvc-failure-analysis
Open

Improve diagnostics for missing ServletContext#51425
xoruddl wants to merge 2 commits into
spring-projects:mainfrom
xoruddl:issue-16936-enable-webmvc-failure-analysis

Conversation

@xoruddl

@xoruddl xoruddl commented Aug 24, 2026

Copy link
Copy Markdown

Improves the diagnostics when Spring MVC resource handling is configured without a ServletContext.

The new failure analyzer detects a failed resourceHandlerMapping with a No ServletContext set cause and advises removing @EnableWebMvc from a test slice configuration or using @WebMvcTest.

Includes unit and integration tests for the analyzer.

Fixes #16936

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 24, 2026
Signed-off-by: itaekyung <taeyun1411@gmail.com>
@xoruddl
xoruddl force-pushed the issue-16936-enable-webmvc-failure-analysis branch from ccffb89 to 9e8ab3c Compare August 24, 2026 14:02

@wilkinsona wilkinsona left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. As the test demonstrates, the analysis will kick in even when the test's configuration isn't using @EnableWebMvc. This results in a misleading action for correcting the problem.

Signed-off-by: xoruddl <taeyun1411@gmail.com>
@xoruddl

xoruddl commented Aug 25, 2026

Copy link
Copy Markdown
Author

Thank you for the feedback. You are right that relying only on the exception message and bean name could result in misleading guidance.

I have updated the analyzer so that it is loaded from spring-boot-webmvc and only produces an analysis when an @EnableWebMvc configuration is actually present. The analysis now also identifies the configuration class or classes where @EnableWebMvc was found and provides guidance for choosing @SpringBootTest or @WebMvcTest when a web test configuration is required.

I have replaced the synthetic integration test with one that reproduces the failure using @EnableWebMvc. I have also added negative tests for a configuration without @EnableWebMvc, a failure involving a different bean, and a failure with a different message.

Thank you again for pointing this out. Please let me know if you think another approach would be preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

3 participants