Skip to content

ContextLoader incorrectly refreshes already refreshed context [SPR-9996] #14630

@spring-projects-issues

Description

@spring-projects-issues

Paul Tomlin opened SPR-9996 and commented

Referring to org.springframework.web.context.ContextLoader

JavaDocs for ContextLoader#ContextLoader(WebApplicationContext) state:

The context may or may not yet be refreshed. If it (a) is an implementation of ConfigurableWebApplicationContext and (b) has not already been refreshed (the recommended approach), then the following will occur:

  • If the given context has not already been assigned an id, one will be assigned to it
  • ServletContext and ServletConfig objects will be delegated to the application context
  • customizeContext(javax.servlet.ServletContext, org.springframework.web.context.ConfigurableWebApplicationContext) will be called
  • Any ApplicationContextInitializers specified through the "contextInitializerClasses" init-param will be applied.
  • refresh() will be called

If the context has already been refreshed or does not implement ConfigurableWebApplicationContext, none of the above will occur under the assumption that the user has performed these actions (or not) per his or her specific needs.

However, it appears that a context provided to the constructor which has already been refreshed, is again refreshed.

ContextLoader#initWebApplicationContext(ServletContext) checks if the context is a ConfigurableWebApplicationContext but no check appears to be made for ConfigurableApplicationContext#isActive(), or Lifecycle#isRunning()


Affects: 3.1.3

Issue Links:

Referenced from: commits 701c5f1, b720804

Backported to: 3.1.4

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions