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;
}
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");
}
}
}
}
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);
}
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);
}
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.");
}
}
}
Aggregations