Spring Framework GenericWebApplicationContext - 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 GenericWebApplicationContext class.

This code example shows how to use the following methods:getBeanFactory, refresh
 
	private NativeWebRequest webRequest; 
 
	@Before 
	public void setUp() throws Exception { 
		GenericWebApplicationContext context = new GenericWebApplicationContext(); 
		context.refresh(); 
		resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory()); 
 
		Method method = getClass().getMethod("params", int.class, String.class, String.class); 
		paramSystemProperty = new MethodParameter(method, 0); 
		paramContextPath = new MethodParameter(method, 1); 
		paramNotSupported = new MethodParameter(method, 2); 
 
		webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse()); 
 
		// Expose request to the current thread (for SpEL expressions) 
		RequestContextHolder.setRequestAttributes(webRequest); 
	} 
 
7
CodeRank
This code example shows how to use the following methods:refresh, registerBeanDefinition
	private static final String NAME = "scoped"; 
 
 
	private WebApplicationContext initApplicationContext(String scope) { 
		MockServletContext sc = new MockServletContext(); 
		GenericWebApplicationContext ac = new GenericWebApplicationContext(sc); 
		GenericBeanDefinition bd = new GenericBeanDefinition(); 
		bd.setBeanClass(DerivedTestBean.class); 
		bd.setScope(scope); 
		ac.registerBeanDefinition(NAME, bd); 
		ac.refresh(); 
		return ac; 
	} 
 
	@Test 
	public void testRequestScope() { 
		WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_REQUEST); 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); 
		RequestContextHolder.setRequestAttributes(requestAttributes); 
7
CodeRank
This code example shows how to use the following methods:refresh
	private static final String NAME = "scoped"; 
 
 
	private ConfigurablePortletApplicationContext initApplicationContext(String scope) { 
		MockServletContext sc = new MockServletContext(); 
		GenericWebApplicationContext rac = new GenericWebApplicationContext(sc); 
		rac.refresh(); 
		PortletContext pc = new ServletWrappingPortletContext(sc); 
		StaticPortletApplicationContext ac = new StaticPortletApplicationContext(); 
		ac.setParent(rac); 
		ac.setPortletContext(pc); 
		GenericBeanDefinition bd = new GenericBeanDefinition(); 
		bd.setBeanClass(DerivedTestBean.class); 
		bd.setScope(scope); 
		ac.registerBeanDefinition(NAME, bd); 
		ac.refresh(); 
		return ac; 
	} 
 
	@Test 
7
CodeRank
This code example shows how to use the following methods:getBeanFactory, refresh
 
	private NativeWebRequest webRequest; 
 
	@Before 
	public void setUp() throws Exception { 
		GenericWebApplicationContext context = new GenericWebApplicationContext(); 
		context.refresh(); 
		resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory()); 
 
		Method method = getClass().getMethod("params", String.class, String[].class, String.class, String.class, Map.class); 
		paramNamedDefaultValueStringHeader = new MethodParameter(method, 0); 
		paramNamedValueStringArray = new MethodParameter(method, 1); 
		paramSystemProperty = new MethodParameter(method, 2); 
		paramContextPath = new MethodParameter(method, 3); 
		paramNamedValueMap = new MethodParameter(method, 4); 
 
		servletRequest = new MockHttpServletRequest(); 
		webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse()); 
 
		// Expose request to the current thread (for SpEL expressions) 
7
CodeRank
This code example shows how to use the following methods:
	private MockHttpServletResponse response; 
 
 
	@Before 
	public void setUp() { 
		this.registry = new ResourceHandlerRegistry(new GenericWebApplicationContext(), new MockServletContext()); 
		this.registration = registry.addResourceHandler("/resources/**"); 
		this.registration.addResourceLocations("classpath:org/springframework/web/servlet/config/annotation/"); 
		this.response = new MockHttpServletResponse(); 
	} 
 
	@Test 
	public void noResourceHandlers() throws Exception { 
		this.registry = new ResourceHandlerRegistry(new GenericWebApplicationContext(), new MockServletContext()); 
		assertNull(this.registry.getHandlerMapping()); 
	} 
 
	@Test 
	public void mapPathToLocation() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
6
CodeRank
This code example shows how to use the following methods:refresh, registerBeanDefinition
 
        ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", true, false);
 
        // Servlet address is defined with the bean name 
        // try to avoid xml config (dont sacrifice type safety) 
        GenericWebApplicationContext genericWebApplicationContext = new GenericWebApplicationContext();
        genericWebApplicationContext.registerBeanDefinition("/loginService",
                BeanDefinitionBuilder.genericBeanDefinition(HttpInvokerServiceExporter.class).
                        addPropertyValue("service", loginService).
                        addPropertyValue("serviceInterface", LoginService.class.getName()).
                        getBeanDefinition()); 
        genericWebApplicationContext.registerBeanDefinition("/copperMonitoringService",
                BeanDefinitionBuilder.genericBeanDefinition(HttpInvokerServiceExporter.class).
                        addPropertyValue("service", copperMonitoringService).
                        addPropertyValue("serviceInterface", CopperMonitoringService.class.getName()).
                        addPropertyValue("remoteInvocationExecutor", remoteInvocationExecutor).
                        getBeanDefinition()); 
        genericWebApplicationContext.refresh();
 
        DispatcherServlet dispatcherServlet = new DispatcherServlet(genericWebApplicationContext);

6
CodeRank
This code example shows how to use the following methods:getDefaultListableBeanFactory, refresh, registerShutdownHook
	public ApplicationContext loadContext(String... locations) throws Exception { 
		if (logger.isDebugEnabled()) { 
			logger.debug("Loading ApplicationContext for locations [" 
					+ StringUtils.arrayToCommaDelimitedString(locations) + "]."); 
		} 
		GenericWebApplicationContext context = new GenericWebApplicationContext(); 
		prepareContext(context); 
		customizeBeanFactory(context.getDefaultListableBeanFactory()); 
		createBeanDefinitionReader(context).loadBeanDefinitions(locations); 
		AnnotationConfigUtils.registerAnnotationConfigProcessors(context); 
		customizeContext(context); 
		context.refresh(); 
		context.registerShutdownHook(); 
		return context; 
	} 
 
	protected void customizeContext(GenericWebApplicationContext context) { 
	} 
 
	protected void customizeBeanFactory(DefaultListableBeanFactory defaultListableBeanFactory) { 
5
CodeRank