@Override public void setServletContext(ServletContext servletContext) { if (this.handshakeHandler instanceof ServletContextAware) { ((ServletContextAware) this.handshakeHandler).setServletContext(servletContext); } }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (getServletContext() != null && bean instanceof ServletContextAware) { ((ServletContextAware) bean).setServletContext(getServletContext()); } if (getServletConfig() != null && bean instanceof ServletConfigAware) { ((ServletConfigAware) bean).setServletConfig(getServletConfig()); } return bean; }
@Override protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException { return context.getBean(name, ViewPreparer.class); }
@Test public void register() throws ServletException { initializer.onStartup(servletContext); assertTrue(eventListener instanceof ContextLoaderListener); ContextLoaderListener cll = (ContextLoaderListener) eventListener; cll.contextInitialized(new ServletContextEvent(servletContext)); WebApplicationContext applicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); assertTrue(applicationContext.containsBean(BEAN_NAME)); assertTrue(applicationContext.getBean(BEAN_NAME) instanceof MyBean); }
/** * Protected constructor. Not intended for direct instantiation. * @see MockMvcBuilders#webAppContextSetup(WebApplicationContext) */ protected DefaultMockMvcBuilder(WebApplicationContext webAppContext) { Assert.notNull(webAppContext, "WebApplicationContext is required"); Assert.notNull(webAppContext.getServletContext(), "WebApplicationContext must have a ServletContext"); this.webAppContext = webAppContext; }
/** * {@inheritDoc} * <p>Replace {@code Servlet}-related property sources. */ @Override protected void initPropertySources() { ConfigurableEnvironment env = getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, this.servletConfig); } }
/** * {@inheritDoc} * <p>Replace {@code Servlet}-related property sources. */ @Override protected void initPropertySources() { ConfigurableEnvironment env = getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, null); } }
@Override public void initialize(ConfigurableWebApplicationContext applicationContext) { applicationContext.getServletContext().setAttribute("initialized", "true"); } }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); registerDispatcherServlet(servletContext); }
/** * Close the root web application context. */ @Override public void contextDestroyed(ServletContextEvent event) { closeWebApplicationContext(event.getServletContext()); ContextCleanupListener.cleanupAttributes(event.getServletContext()); }
/** * Initialize the root web application context. */ @Override public void contextInitialized(ServletContextEvent event) { initWebApplicationContext(event.getServletContext()); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { registerContextLoaderListener(servletContext); }
@Before public void setUp() throws Exception { servletContext = new MyMockServletContext(); initializer = new MyContextLoaderInitializer(); eventListener = null; }
@Override public void initialize(UnknownApplicationContext applicationContext) { applicationContext.unheardOf(); } }
private static CompositeUriComponentsContributor getUriComponentsContributor() { WebApplicationContext wac = getWebApplicationContext(); if (wac != null) { try { return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class); } catch (NoSuchBeanDefinitionException ex) { // Ignore } } return defaultUriComponentsContributor; }
@Override public void setServletContext(ServletContext servletContext) { if (this.sockJsService instanceof ServletContextAware) { ((ServletContextAware) this.sockJsService).setServletContext(servletContext); } }
@Override public void initialize(ConfigurableWebApplicationContext applicationContext) { ServletContext ctx = applicationContext.getServletContext(); // type-safe access to servlet-specific methods ctx.setAttribute("initialized", true); } }
@Override public void setServletContext(ServletContext servletContext) { for (ViewResolver viewResolver : this.viewResolvers) { if (viewResolver instanceof ServletContextAware) { ((ServletContextAware)viewResolver).setServletContext(servletContext); } } }
@Override public void setServletContext(ServletContext servletContext) { if (this.handshakeHandler instanceof ServletContextAware) { ((ServletContextAware) this.handshakeHandler).setServletContext(servletContext); } }
@Override public void setServletContext(ServletContext servletContext) { RequestUpgradeStrategy strategy = getRequestUpgradeStrategy(); if (strategy instanceof ServletContextAware) { ((ServletContextAware) strategy).setServletContext(servletContext); } }