Skip to content
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

ContextLoaderListener overwriting config location set in WebApplicationContext [SPR-8510] #13156

Closed
spring-projects-issues opened this issue Jul 5, 2011 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Craig Walls opened SPR-8510 and commented

When creating a ContextLoaderListener programmatically in a WebApplicationInitializer, I'd expect to be able to set the config location on the context like this:

XmlWebApplicationContext context = new
XmlWebApplicationContext();
context.setConfigLocation("/WEB-INF/spring/root-context.xml");
ContextLoaderListener contextLoaderListener = new
ContextLoaderListener(context);
container.addListener(contextLoaderListener);

Doing so would be consistent with how I can set the config location when programmatically creating a DispatcherServlet.

But this doesn't work because ContextLoader.configureAndRefreshWebApplicationContext() overwrites the config location with whatever the "contextConfigLocation" init parameter is set to (if it's not set, then it sets it to null, which in the case of XmlWebApplicationContext makes it try to load the default applicationContext.xml).

The workaround is to set the "contextConfigLocation" init param. But this is inconsistent with how it works with DispatcherServlet.


Affects: 3.1 M2

Referenced from: commits 23e58aa

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Thanks, Craig. This is fixed.

commit 79cdb9e136f790c8100699d9bba476782cd02c40 (HEAD, trunk, master)
Author: Chris Beams <cbeams@vmware.com>
Date:   Mon Dec 12 14:42:24 2011 +0000

    Preserve programmatically set context config locations
    
    Prior to this fix, ContextLoader(Listener)'s would overwrite any
    value set directly against a WebApplicationContext's #setConfigLocation
    method. This is a likely scenario when using Spring 3.1's new
    WebApplicationInitializer support.
    
    Now a check is performed to ensure that the ContextLoader init-param
    value is non-null before doing the overwriting.
    
    Added tests to ensure that all expected precedence, overwriting and
    defaulting of context config locations works as expected.
    
    Issue: SPR-8510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant