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