Spring Framework XmlWebApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework XmlWebApplicationContext class.

This code example shows how to use the following methods:getBean, refresh, setConfigLocations, setServletContext
	private HandlerMapping hm; 
 
	@Override 
	public void setUp() throws Exception { 
		MockServletContext sc = new MockServletContext(""); 
		this.wac = new XmlWebApplicationContext(); 
		this.wac.setServletContext(sc); 
		this.wac.setConfigLocations(new String[] {LOCATION}); 
		this.wac.refresh(); 
		this.hm = (HandlerMapping) this.wac.getBean("mapping"); 
	} 
 
	public void testIndexUri() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index"); 
		HandlerExecutionChain chain = this.hm.getHandler(request); 
		assertEquals(this.wac.getBean("index"), chain.getHandler()); 
	} 
 
	public void testMapSimpleUri() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/welcome"); 
8
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocations, setServletContext
	private HandlerMapping hm4; 
 
	@Override 
	public void setUp() throws Exception { 
		MockServletContext sc = new MockServletContext(""); 
		this.wac = new XmlWebApplicationContext(); 
		this.wac.setServletContext(sc); 
		this.wac.setConfigLocations(new String[] {LOCATION}); 
		this.wac.refresh(); 
		this.hm = (HandlerMapping) this.wac.getBean("mapping"); 
		this.hm2 = (HandlerMapping) this.wac.getBean("mapping2"); 
		this.hm3 = (HandlerMapping) this.wac.getBean("mapping3"); 
		this.hm4 = (HandlerMapping) this.wac.getBean("mapping4"); 
	} 
 
	public void testIndexUri() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index"); 
		HandlerExecutionChain chain = this.hm.getHandler(request); 
		assertEquals(this.wac.getBean("index"), chain.getHandler()); 
 
8
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocations, setServletContext
	private HandlerMapping hm4; 
 
	@Override 
	public void setUp() throws Exception { 
		MockServletContext sc = new MockServletContext(""); 
		this.wac = new XmlWebApplicationContext(); 
		this.wac.setServletContext(sc); 
		this.wac.setConfigLocations(new String[] {LOCATION}); 
		this.wac.refresh(); 
		this.hm = (HandlerMapping) this.wac.getBean("mapping"); 
		this.hm2 = (HandlerMapping) this.wac.getBean("mapping2"); 
		this.hm3 = (HandlerMapping) this.wac.getBean("mapping3"); 
		this.hm4 = (HandlerMapping) this.wac.getBean("mapping4"); 
	} 
 
	public void testIndexUri() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); 
		HandlerExecutionChain chain = this.hm.getHandler(request); 
		assertEquals(this.wac.getBean("index"), chain.getHandler()); 
	} 
8
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocation, setServletContext
public class SimpleBeanAccessTests { 
	 
	@Test 
	public void test() { 
 
		XmlWebApplicationContext wac = new XmlWebApplicationContext(); 
		wac.setConfigLocation("file:src/main/webapp/WEB-INF/spring/root-context.xml"); 
		wac.setServletContext(new MockServletContext()); 
		wac.refresh(); 
		 
		ServletWebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest()); 
		RequestContextHolder.setRequestAttributes(webRequest); 
		 
		MyBeanClass myBeanClass = wac.getBean("myBeanClass", MyBeanClass.class); 
		assertNull(myBeanClass); 
		 
		MyBeanClass myProxiedBeanClass = wac.getBean("myProxiedBeanClass", MyBeanClass.class); 
		assertNotNull(myProxiedBeanClass); 
		assertEquals("foo", myProxiedBeanClass.getFoo());	// this will cause NPE 
 

7
CodeRank
This code example shows how to use the following methods:setConfigLocation, setEnvironment, setServletContext
    private XmlWebApplicationContext webApplicationContext; 
    private MockEnvironment environment; 
 
    @Before 
    public void setUp() { 
        webApplicationContext = new XmlWebApplicationContext(); 
        environment = new MockEnvironment(); 
        webApplicationContext.setEnvironment(environment); 
        webApplicationContext.setServletContext(new MockServletContext()); 
        new YamlServletProfileInitializer().initialize(webApplicationContext); 
        webApplicationContext.setConfigLocation("file:./src/main/webapp/WEB-INF/spring-servlet.xml"); 
    } 
    /** 
     * We have a condition in the AutzhAuthenticationManager that automatically 
     * fails a password validation for zero length password. 
     * This test prevents that the authzAuthenticationMgr gets swapped out without 
     * the developer being notified. 
     * @throws Exception 
     */ 
    @Test 
7
CodeRank
This code example shows how to use the following methods:refresh, setConfigLocations, setDisplayName, setParent, setServletContext
		this.displayName = name; 
	} 
	 
	public void afterPropertiesSet() throws Exception { 
		if (loadContext) { 
			context = new XmlWebApplicationContext(); 
			context.setParent(parent); 
			context.setDisplayName(displayName); 
			context.setConfigLocations(configLocations); 
			context.setServletContext(servletContext); 
			context.refresh(); 
		} 
	} 
 
	public ApplicationContext getContext() { 
		return this.context; 
	} 
	 
} 
7
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocation, setParent, setServletContext
        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()); 

7
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocation, setServletContext
    private static TestClient testClient; 
    private static String loginToken; 
 
    @BeforeClass 
    public static void setUp() throws Exception { 
        webApplicationContext = new XmlWebApplicationContext(); 
        webApplicationContext.setServletContext(new MockServletContext()); 
        new YamlServletProfileInitializer().initialize(webApplicationContext); 
        webApplicationContext.setConfigLocation("file:./src/main/webapp/WEB-INF/spring-servlet.xml"); 
        webApplicationContext.refresh(); 
        FilterChainProxy springSecurityFilterChain = webApplicationContext.getBean(FilterChainProxy.class); 
 
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilter(springSecurityFilterChain) 
                        .build(); 
        testClient = new TestClient(mockMvc); 
        loginToken = testClient.getClientCredentialsOAuthAccessToken("login", "loginsecret", null); 
    } 
 
    @AfterClass 
    public static void tearDown() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:getBean, refresh, setConfigLocation, setServletContext
        "JwIDAQAB\n" + 
        "-----END PUBLIC KEY-----"; 
 
    @Before 
    public void setUp() throws Exception { 
        webApplicationContext = new XmlWebApplicationContext(); 
        webApplicationContext.setServletContext(new MockServletContext()); 
        new YamlServletProfileInitializer().initialize(webApplicationContext); 
        webApplicationContext.setConfigLocation("file:./src/main/webapp/WEB-INF/spring-servlet.xml"); 
        webApplicationContext.refresh(); 
        FilterChainProxy springSecurityFilterChain = webApplicationContext.getBean(FilterChainProxy.class); 
 
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilter(springSecurityFilterChain) 
            .build(); 
        testClient = new TestClient(mockMvc); 
 
        SignerProvider provider = webApplicationContext.getBean(SignerProvider.class); 
        provider.setSigningKey(signKey); 
        provider.setVerifierKey(verifyKey); 
        provider.afterPropertiesSet(); 

7
CodeRank
This code example shows how to use the following methods:setConfigLocation
 */ 
public class WebAppInitializer implements WebApplicationInitializer { 
 
  @Override 
  public void onStartup(ServletContext container) { 
    XmlWebApplicationContext appContext = new XmlWebApplicationContext(); 
    appContext.setConfigLocation("/WEB-INF/applicationContext.xml"); 
 
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:setConfigLocation
 */ 
public class WebAppInitializer implements WebApplicationInitializer { 
 
  @Override 
  public void onStartup(ServletContext container) { 
    XmlWebApplicationContext appContext = new XmlWebApplicationContext(); 
    appContext.setConfigLocation("/WEB-INF/applicationContext.xml"); 
 
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:refresh, setConfigLocation
    @BeforeClass 
    public static void initialize() { 
        applicationContext = new ClassPathXmlApplicationContext("classpath:spring/resource-bundle.xml"); 
        assertNotNull(applicationContext); 
         
        webApplicationContext = new XmlWebApplicationContext(); 
        webApplicationContext.setConfigLocation("file:src/main/webapp/WEB-INF/spring/*-context.xml"); 
        webApplicationContext.refresh(); 
        assertNotNull(webApplicationContext); 
    } 
 
    @Test 
    public void testApplicationContext() { 
        LocalValidatorFactoryBean factory = applicationContext.getBean("validator", LocalValidatorFactoryBean.class); 
        Validator validator = factory.getValidator(); 
        Registration registration = new Registration(); 
        Set<ConstraintViolation<Registration>> violations = validator.validate(registration); 
        assertEquals("ABN is required.", violations.iterator().next().getMessage()); 
    } 
 
6
CodeRank
This code example shows how to use the following methods:refresh, setServletContext
        context.addInitParameter("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider"); 
        return context; 
    } 
 
    private static XmlWebApplicationContext createRootApplicationContext(MockServletContext servletContext) { 
        XmlWebApplicationContext applicationContext = new XmlWebApplicationContext(); 
        applicationContext.setServletContext(servletContext); 
        applicationContext.refresh(); 
        return applicationContext; 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
package __TOP_LEVEL_PACKAGE__.__SEGMENT_PACKAGE__; 
 
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 
import org.springframework.web.context.support.XmlWebApplicationContext; 
 
import com.google.appengine.api.utils.SystemProperty; 
 
public class CustomXmlWebApplicationContext extends XmlWebApplicationContext 
{ 
	protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) 
	{ 
		super.initBeanDefinitionReader(beanDefinitionReader); 
		if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) 
		{ 
			beanDefinitionReader.setValidating(false); 
		} 
		beanDefinitionReader.setValidating(false); 
	} 
} 

6
CodeRank
This code example shows how to use the following methods:close, stop
	} 
	 
	public void stopAndCloseApplicationContext() { 
		try { 
			XmlWebApplicationContext ctx = (XmlWebApplicationContext) getWebApplicationContext(); 
			ctx.stop(); 
			ctx.close(); 
		} 
		catch (Exception e) { 
			log.error("Exception while stopping and closing static content dispatcher servlet context: ", e); 
		} 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:
import org.springframework.web.context.support.XmlWebApplicationContext; 
 
/** 
 * @author Brian Wing Shun Chan 
 */ 
public class TunnelApplicationContext extends XmlWebApplicationContext { 
 
	@Override 
	public void setParent(ApplicationContext applicationContext) { 
		if (applicationContext == null) { 
			BeanLocatorImpl beanLocatorImpl = 
				(BeanLocatorImpl)PortalBeanLocatorUtil.getBeanLocator(); 
 
			applicationContext = beanLocatorImpl.getApplicationContext(); 
		} 
 
		super.setParent(applicationContext); 
	} 
 
	@Override 
6
CodeRank
This code example shows how to use the following methods:refresh, setConfigLocations, setParent
public class XmlRestWebApplicationContext extends XmlWebApplicationContext { 
 
    private boolean active; 
    private String cfgLocationsType; 
 
    public XmlRestWebApplicationContext(String[] configLocations, String cfgLocationsType, boolean refresh, ApplicationContext parent) { 
        this.setConfigLocations(configLocations); 
        this.setParent(parent); 
        this.cfgLocationsType = cfgLocationsType; 
        if (refresh) { 
            this.refresh(); 
        } 
    } 
 
    @Override 
    protected Resource getResourceByPath(String path) { 
        if (getServletContext() == null) { 
            // Load Resource based on cfgLocationsType. 
            if (SpringConfiguration.FILE_CONFIG.equals(cfgLocationsType)) { 
                return new FileSystemResource(path); 

6
CodeRank
This code example shows how to use the following methods:
public class NimbusXmlWebApplicationContext extends XmlWebApplicationContext { 
 
    NimbusHomePathResolver nimbusHomePathResolver; 
 
    public NimbusXmlWebApplicationContext() { 
        super(); 
    } 
 
    @Override 
    protected Resource getResourceByPath(String path) { 
 
        if (this.nimbusHomePathResolver == null) { 
            this.nimbusHomePathResolver = new NimbusHomePathResolver(); 
        } 
 
        final String resolved = this.nimbusHomePathResolver.resolvePath(path); 
 
        if (resolved != null) { 
            return new FileSystemResource(resolved); 
        } 
5
CodeRank
This code example shows how to use the following methods:
 * Extension of Spring's {@link org.springframework.web.context.support.XmlWebApplicationContext} that includes hooks to 
 * resolve some injections into Spring beans as Tapestry services. When using the Tapestry/Spring Integration Library, 
 * this class (or a subclass) must be the configured context class.  If not specified, this  class is the default 
 * context class. 
 */ 
public class TapestryApplicationContext extends XmlWebApplicationContext 
{ 
    @Override 
    protected DefaultListableBeanFactory createBeanFactory() 
    { 
        Registry registry = (Registry) getServletContext().getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME); 
 
        if (registry == null) 
            throw new IllegalStateException( 
                    "Expected a Tapestry IoC Registry to be stored in the ServletContext, but the attribute was null."); 
 
        return new TapestryBeanFactory(getInternalParentBeanFactory(), registry); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:refresh, setParent
import java.io.IOException; 
 
public final class SingleResourceWebChildContext extends XmlWebApplicationContext { 
    private Resource res; 
 
    SingleResourceWebChildContext(Resource res, ApplicationContext parent) { 
        this.res = res; 
        setParent(parent); 
        refresh(); 
    } 
 
    protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException { 
        reader.loadBeanDefinitions(res); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setConfigLocations
	 * 		<li>etc. 
	 * </ul> 
	 */ 
	public static ContextMockMvcBuilder xmlConfigSetup(String... configLocations) {
		Assert.notEmpty(configLocations, "At least one XML config location is required");
		XmlWebApplicationContext context = new XmlWebApplicationContext();
		context.setConfigLocations(configLocations);
		return new ContextMockMvcBuilder(context);
	} 
 
	/** 
	 * Build a {@link MockMvc} from a fully initialized {@link WebApplicationContext} 
	 * The context must have been setup with a {@link ServletContext} and refreshed. 
	 */ 
	public static InitializedContextMockMvcBuilder webApplicationContextSetup(WebApplicationContext context) {
		return new InitializedContextMockMvcBuilder(context);
	} 
 
	/** 
	 * Build a {@link MockMvc} by providing @{@link Controller} instances and configuring 
5
CodeRank
This code example shows how to use the following methods:
 * Overrides <code>getResourceByPath</code> so that relative paths are relative to the Pentaho solution repository's 
 * system directory instead of being relative to servlet context root. 
 *  
 * @author mlowery 
 */ 
public class PentahoSolutionSpringApplicationContext extends XmlWebApplicationContext { 
 
  protected Resource getResourceByPath( String path ) { 
    Resource resource = null; 
    String solutionPath = PentahoHttpSessionHelper.getSolutionPath( getServletContext() ); 
    if ( solutionPath != null ) { 
      File file = new File( solutionPath + File.separator + "system" + File.separator + path ); //$NON-NLS-1$ 
      resource = new FileSystemResource( file ); 
    } else { 
      resource = super.getResourceByPath( path ); 
    } 
    return resource; 
  } 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 *        &lt;param-value&gt;${org.intalio.tempo.configDirectory}/tempo-tms.xml &lt;/param-value&gt;<br/> 
 *     &lt;/context-param&gt;<br/><br/> 
 * 
 * System properties must be enclosed within "${" prefix and "}" suffix strings. 
 */ 
public class SysPropWebApplicationContext extends XmlWebApplicationContext { 
 
    @Override 
    public Resource getResource(String location) { 
        location = SystemPropertyUtils.resolvePlaceholders(location); 
        return super.getResource(location); 
    } 
     
} 
5
CodeRank
This code example shows how to use the following methods:
	 *  
	 * @return application context instance 
	 */ 
	protected ConfigurableWebApplicationContext newApplicationContext() 
	{ 
		return new XmlWebApplicationContext(); 
	} 
 
	/** 
	 * @see IWebApplicationFactory#createApplication(WicketFilter) 
	 */ 
	@Override 
	public WebApplication createApplication(final WicketFilter filter) 
	{ 
		ServletContext servletContext = filter.getFilterConfig().getServletContext(); 
 
		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); 
 
		if (getContextConfigLocation(filter) != null) 
		{ 
5
CodeRank
This code example shows how to use the following methods:
 * Time: 9:42 PM 
 */ 
public class Initializer implements WebApplicationInitializer { 
    @Override 
    public void onStartup(ServletContext servletContext) throws ServletException { 
        WebApplicationContext rootContext = new XmlWebApplicationContext(); 
        servletContext.addListener(new ContextLoaderListener(rootContext)); 
 
        AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); 
        mvcContext.register(Config.class); 
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext)); 
        dispatcher.addMapping("/*"); 
        servletContext.getServletRegistration("jsp").addMapping("/WEB-INF/jsp/*"); 
 
        FilterRegistration.Dynamic osiv = servletContext.addFilter("osiv", new OpenEntityManagerInViewFilter()); 
        osiv.addMappingForUrlPatterns(null, false, "/*"); 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:
package io.cattle.platform.context; 
 
import org.springframework.web.context.support.XmlWebApplicationContext; 
 
public class DefaultedXmlWebApplicationContext extends XmlWebApplicationContext { 
 
    private static final String[] DEFAULT_LOCATIONS = new String[] { "classpath:META-INF/cattle/webApplicationContext.xml" }; 
 
    @Override 
    protected String[] getDefaultConfigLocations() { 
        return DEFAULT_LOCATIONS; 
    } 
 
} 
4
CodeRank
This code example shows how to use the following methods:
 * XmlWebApplicationContext variant adding support for classpath 
 * scanning in JBoss AS 5, using the VFS file system. 
 * 
 * @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a> 
 */ 
public class VFSXmlWebApplicationContext extends XmlWebApplicationContext { 
 
    @Override 
    protected ResourcePatternResolver getResourcePatternResolver() { 
        return new VFSServletContextResourcePatternResolver( 
                new WebApplicationContextAwareVFSResourceLoader(getClassLoader())); 
    } 
 
    /** 
     * Customization of {@link VFSResourceLoader} that delegates to the owner class 
     * (i.e. XmlWebApplicationContext) for retrieving resources by path, allowing 
     * for ServletContextResources to be returned in this case. 
     */ 
    private class WebApplicationContextAwareVFSResourceLoader extends VFSResourceLoader { 
 
4
CodeRank
This code example shows how to use the following methods:refresh, setServletContext
 
    public RoseWebAppContext(ServletContext servletContext, String scope, boolean refresh) { 
        this(servletContext, new LoadScope(scope, "controllers"), refresh); 
    } 
 
    public RoseWebAppContext(ServletContext servletContext, LoadScope scope, boolean refresh) { 
        this.scope = scope; 
        this.setServletContext(servletContext); 
        if (refresh) { 
            refresh(); 
        } 
    } 
 
    /** 
     * 返回对应类型的唯一 Bean, 包括可能的祖先 {@link ApplicationContext} 中对应类型的 Bean. 
     *  
     * @param beanType - Bean 的类型 
     *  
     * @throws BeansException 
     */ 
5
CodeRank
This code example shows how to use the following methods:getBean
        request = mockRequest; 
        FakeUIFWApplicationState state = new FakeUIFWApplicationState(); 
        User currentUser = new User("test1", new String[] { "test/test1" }, "token1"); 
        state.setCurrentUser(currentUser); 
        request.getSession().setAttribute("APPLICATION_STATE", state); 
        securedController = (SecuredController) context.getBean("tasksController"); 
        try { 
            ModelAndView mav = securedController.processFormSubmission(request, response, null, new BindException(currentUser, "test")); 
            Assert.fail("Invalid Action exception expected"); 
        } catch (Exception e) { 
 
        } 
 
    } 
 
    @Test 
    public void testProcessFormSubmissionValidActionWithUser() throws Exception { 
        MockHttpServletRequest mockRequest = new MockHttpServletRequest(); 
        mockRequest.addParameter("actionName", "default"); 
        request = mockRequest; 
4
CodeRank
This code example shows how to use the following methods:
 *  &lt;/dependency> 
 *  </pre> 
 * </li> 
 * </ul> 
 */ 
public class ClassReloadingXMLWebApplicationContext extends XmlWebApplicationContext implements FilesystemAlterationListener { 
    private static final Logger LOG = LoggerFactory.getLogger(ClassReloadingXMLWebApplicationContext.class); 
 
    protected ReloadingClassLoader classLoader; 
    protected FilesystemAlterationMonitor fam; 
 
    protected ClassReloadingBeanFactory beanFactory; 
    //reload the runtime configuration when a change is detected 
    private boolean reloadConfig; 
 
    public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext, boolean reloadConfig) { 
        this.reloadConfig = reloadConfig; 
 
        classLoader = new ReloadingClassLoader(ClassReloadingXMLWebApplicationContext.class.getClassLoader()); 
 
3
CodeRank