Skip to content

MockMvcBuilders should populate ServletContextAttribute WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE to enable view technologies use WebApplicationContextUtils.getRequiredWebApplicationContext(…) [SPR-12553] #17155

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-12553 and commented

Wehen setting up a MockMvc instance from a WebApplicationContext the ServletContext attribute WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE does not get populated. View technologies used for rendering views often lookup the ApplicationContext using WebApplicationContextUtils.getRequiredWebApplicationContext(…). That method expects the ApplicationContext to be registered under said attribute.

I currently work around the issue by manually setting the attribute:

context.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);

Affects: 4.1.3

Referenced from: commits f6d2fe4, 32aafb2, 33b9bd7

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions