Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 16, 2012 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 16, 2012

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed now, syncing the code with FrameworkServlet which performs an isActive check on a WebApplicationContext instance provided there already.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2.1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants