Code example for XmlWebApplicationContext

Methods: getBean, refresh, setConfigLocation, setParent, setServletContext

0
        String wrappedServletName = getServletName(); 
 
        // Parent Context loaded by ContextLoaderListener 
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); 
 
        XmlWebApplicationContext xmppContext = new XmlWebApplicationContext(); 
        xmppContext.setServletContext(getServletContext()); 
        xmppContext.setParent(wac); 
        xmppContext.setConfigLocation("/WEB-INF/" + getServletName() + "-xmpp.xml"); 
        xmppContext.refresh(); 
 
        Object bean = xmppContext.getBean(wrappedServletName); 
 
        if (!(bean instanceof XmppServlet)) { 
            throw new IllegalArgumentException("Servlet has to be an instance of XMPPServlet"); 
        } 
 
        target = (XmppServlet) bean; 
 
        target.init(getServletConfig()); 
         
        getServletContext().setAttribute(APPLICATION_CONTEXT, xmppContext); 
    } 
 
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { 
        try { 
            this.target.service(request, response);