use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.
the class GroovyPagesServlet method initFrameworkServlet.
@Override
protected void initFrameworkServlet() throws ServletException, BeansException {
context = getServletContext();
context.log("GSP servlet initialized");
context.setAttribute(SERVLET_INSTANCE, this);
final WebApplicationContext webApplicationContext = getWebApplicationContext();
grailsAttributes = GrailsFactoriesLoader.loadFactoriesWithArguments(GrailsApplicationAttributes.class, getClass().getClassLoader(), new Object[] { context }).get(0);
webApplicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
groovyPagesTemplateEngine = webApplicationContext.getBean(GroovyPagesTemplateEngine.BEAN_ID, GroovyPagesTemplateEngine.class);
}
use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.
the class GrailsWebUtil method lookupApplication.
/**
* Looks up a GrailsApplication instance from the ServletContext.
*
* @param servletContext The ServletContext
* @return A GrailsApplication or null if there isn't one
*/
public static GrailsApplication lookupApplication(ServletContext servletContext) {
if (servletContext == null) {
return null;
}
GrailsApplication grailsApplication = (GrailsApplication) servletContext.getAttribute(ApplicationAttributes.APPLICATION);
if (grailsApplication != null) {
return grailsApplication;
}
final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) {
return null;
}
return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
}
use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.
the class WebUtils method lookupWebRequestInterceptors.
/**
* Looks up all of the WebRequestInterceptor instances registered with the application
*
* @param servletContext The ServletContext instance
* @return An array of WebRequestInterceptor instances
*/
public static WebRequestInterceptor[] lookupWebRequestInterceptors(ServletContext servletContext) {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
final Collection<WebRequestInterceptor> webRequestInterceptors = wac.getBeansOfType(WebRequestInterceptor.class).values();
return webRequestInterceptors.toArray(new WebRequestInterceptor[webRequestInterceptors.size()]);
}
use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.
the class GrailsLayoutDecoratorMapper method init.
@Override
public void init(Config c, Properties properties, DecoratorMapper parentMapper) throws InstantiationException {
super.init(c, properties, parentMapper);
ServletContext servletContext = c.getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
if (applicationContext != null) {
GrailsApplication grailsApplication = applicationContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
groovyPageLayoutFinder = grailsApplication.getMainContext().getBean("groovyPageLayoutFinder", GroovyPageLayoutFinder.class);
}
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class MockHttpServletRequestBuilder method getFlashMapManager.
private FlashMapManager getFlashMapManager(MockHttpServletRequest request) {
FlashMapManager flashMapManager = null;
try {
ServletContext servletContext = request.getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
flashMapManager = wac.getBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class);
} catch (IllegalStateException ex) {
// ignore
} catch (NoSuchBeanDefinitionException ex) {
// ignore
}
return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager());
}
Aggregations