Search in sources :

Example 76 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class SpringBeanFacesELResolver method getType.

@Override
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        WebApplicationContext wac = getWebApplicationContext(elContext);
        if (wac.containsBean(beanName)) {
            elContext.setPropertyResolved(true);
            return wac.getType(beanName);
        }
    }
    return null;
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 77 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class SpringBeanFacesELResolver method setValue.

@Override
public void setValue(ELContext elContext, Object base, Object property, Object value) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        WebApplicationContext wac = getWebApplicationContext(elContext);
        if (wac.containsBean(beanName)) {
            if (value == wac.getBean(beanName)) {
                // Setting the bean reference to the same value is alright - can simply be ignored...
                elContext.setPropertyResolved(true);
            } else {
                throw new PropertyNotWritableException("Variable '" + beanName + "' refers to a Spring bean which by definition is not writable");
            }
        }
    }
}
Also used : PropertyNotWritableException(javax.el.PropertyNotWritableException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 78 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class HttpRequestHandlerServlet method init.

@Override
public void init() throws ServletException {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    this.target = wac.getBean(getServletName(), HttpRequestHandler.class);
}
Also used : HttpRequestHandler(org.springframework.web.HttpRequestHandler) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 79 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class SpringBeanAutowiringSupport method processInjectionBasedOnServletContext.

/**
	 * Process {@code @Autowired} injection for the given target object,
	 * based on the current root web application context as stored in the ServletContext.
	 * <p>Intended for use as a delegate.
	 * @param target the target object to process
	 * @param servletContext the ServletContext to find the Spring web application context in
	 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
	 */
public static void processInjectionBasedOnServletContext(Object target, ServletContext servletContext) {
    Assert.notNull(target, "Target object must not be null");
    WebApplicationContext cc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
    bpp.processInjection(target);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 80 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class SpringBeanAutowiringSupport method processInjectionBasedOnCurrentContext.

/**
	 * Process {@code @Autowired} injection for the given target object,
	 * based on the current web application context.
	 * <p>Intended for use as a delegate.
	 * @param target the target object to process
	 * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
	 */
public static void processInjectionBasedOnCurrentContext(Object target) {
    Assert.notNull(target, "Target object must not be null");
    WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
    if (cc != null) {
        AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
        bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
        bpp.processInjection(target);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Current WebApplicationContext is not available for processing of " + ClassUtils.getShortName(target.getClass()) + ": " + "Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
        }
    }
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

WebApplicationContext (org.springframework.web.context.WebApplicationContext)103 Test (org.junit.Test)32 ServletContext (javax.servlet.ServletContext)17 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)13 ApplicationContext (org.springframework.context.ApplicationContext)11 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)11 HashMap (java.util.HashMap)9 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)9 MockServletContext (org.springframework.mock.web.test.MockServletContext)8 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)7 Filter (javax.servlet.Filter)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)6 Binding (groovy.lang.Binding)5 BeanBuilder (hudson.util.spring.BeanBuilder)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4