Search in sources :

Example 6 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletContextAwareWithServletContextAndServletConfig.

@Test
public void servletContextAwareWithServletContextAndServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, servletConfig);
    ServletContextAwareBean bean = new ServletContextAwareBean();
    assertThat(bean.getServletContext()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletContext()).as("ServletContext should have been set").isNotNull();
    assertThat(bean.getServletContext()).isEqualTo(servletContext);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletConfig(jakarta.servlet.ServletConfig) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 7 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletConfigAwareWithNullServletContextAndNonNullServletConfig.

@Test
public void servletConfigAwareWithNullServletContextAndNonNullServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, servletConfig);
    ServletConfigAwareBean bean = new ServletConfigAwareBean();
    assertThat(bean.getServletConfig()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletConfig()).as("ServletConfig should have been set").isNotNull();
    assertThat(bean.getServletConfig()).isEqualTo(servletConfig);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletConfig(jakarta.servlet.ServletConfig) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 8 with ServletContextAwareProcessor

use of org.springframework.web.context.support.ServletContextAwareProcessor in project grails-core by grails.

the class GrailsWebApplicationContext method postProcessBeanFactory.

/**
 * Register ServletContextAwareProcessor.
 * @see ServletContextAwareProcessor
 */
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(servletContext));
    beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    beanFactory.registerResolvableDependency(ServletContext.class, servletContext);
    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor)

Example 9 with ServletContextAwareProcessor

use of org.springframework.web.context.support.ServletContextAwareProcessor in project cuba by cuba-platform.

the class CubaClassPathXmlApplicationContext method postProcessBeanFactory.

@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    if (this.servletContext != null) {
        beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext));
        beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    }
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor)

Example 10 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletContextAwareWithServletConfig.

@Test
public void servletContextAwareWithServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletConfig);
    ServletContextAwareBean bean = new ServletContextAwareBean();
    assertThat(bean.getServletContext()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletContext()).as("ServletContext should have been set").isNotNull();
    assertThat(bean.getServletContext()).isEqualTo(servletContext);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletConfig(jakarta.servlet.ServletConfig) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)14 ServletContext (jakarta.servlet.ServletContext)12 Test (org.junit.jupiter.api.Test)12 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)12 ServletConfig (jakarta.servlet.ServletConfig)6 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)6