Athrawn17
Oct 7th, 2005, 06:39 PM
In the FrameworkServlet.initWebApplicationContext() method the context is published as a servlet context attribute. Below is the relevant code.
protected WebApplicationContext initWebApplicationContext(){
...
String attrName = getServletContextAttributeName();
getServletContext().setAttribute(attrName, wac);
...
}
public String getServletContextAttributeName() {
return SERVLET_CONTEXT_PREFIX + getServletName();
}
public static final String SERVLET_CONTEXT_PREFIX = FrameworkServlet.class.getName() + ".CONTEXT.";
This is fine, except that when I use the static method
WebApplicationContextUtils.getWebApplicationContex t(myServletContext);
to get the context this is the code that gets executed:
public static WebApplicationContext getWebApplicationContext(ServletContext sc) {
Object attr = sc.getAttribute(WebApplicationContext.ROOT_WEB_APP LICATION_CONTEXT_ATTRIBUTE);
...
}
String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class + ".ROOT";
Obviously there is a disconnect here. The FrameworkServlet should use the same parameter when setting the servlet context attribute as the Util class is using to obtain it.
Is this a bug or is there a reason that the Framework Servlet is doing this? Note that the ContextLoader class also uses the ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE when publishing the context.
protected WebApplicationContext initWebApplicationContext(){
...
String attrName = getServletContextAttributeName();
getServletContext().setAttribute(attrName, wac);
...
}
public String getServletContextAttributeName() {
return SERVLET_CONTEXT_PREFIX + getServletName();
}
public static final String SERVLET_CONTEXT_PREFIX = FrameworkServlet.class.getName() + ".CONTEXT.";
This is fine, except that when I use the static method
WebApplicationContextUtils.getWebApplicationContex t(myServletContext);
to get the context this is the code that gets executed:
public static WebApplicationContext getWebApplicationContext(ServletContext sc) {
Object attr = sc.getAttribute(WebApplicationContext.ROOT_WEB_APP LICATION_CONTEXT_ATTRIBUTE);
...
}
String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class + ".ROOT";
Obviously there is a disconnect here. The FrameworkServlet should use the same parameter when setting the servlet context attribute as the Util class is using to obtain it.
Is this a bug or is there a reason that the Framework Servlet is doing this? Note that the ContextLoader class also uses the ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE when publishing the context.