Search in sources :

Example 66 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project alfresco-remote-api by Alfresco.

the class AbstractJettyComponent method createWebApplicationContext.

/*
	 * Creates a web application context wrapping a Spring application context (adapted from core spring code in
	 * org.springframework.web.context.ContextLoader)
	 */
protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent) {
    GenericWebApplicationContext wac = (GenericWebApplicationContext) BeanUtils.instantiateClass(GenericWebApplicationContext.class);
    // Assign the best possible id value.
    wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + contextPath);
    wac.setParent(parent);
    wac.setServletContext(sc);
    wac.refresh();
    return wac;
}
Also used : GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Example 67 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project tutorials by eugenp.

the class StudentControllerConfig method onStartup.

@Override
public void onStartup(ServletContext sc) throws ServletException {
    AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.register(WebConfig.class);
    root.setServletContext(sc);
    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));
    DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext());
    ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
    appServlet.setLoadOnStartup(1);
    appServlet.addMapping("/test/*");
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Example 68 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project tutorials by eugenp.

the class MainWebAppInitializer method onStartup.

@Override
public void onStartup(final ServletContext sc) throws ServletException {
    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.register(WebConfig.class);
    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));
    // Handles requests into the application
    final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Example 69 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project tutorials by eugenp.

the class MainWebAppInitializer method onStartup.

/**
 * Register and configure all Servlet container components necessary to power the web application.
 */
@Override
public void onStartup(final ServletContext sc) throws ServletException {
    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("com.baeldung.spring.web.config");
    // root.getEnvironment().setDefaultProfiles("embedded");
    sc.addListener(new ContextLoaderListener(root));
    // Handles requests into the application
    final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setLoadOnStartup(1);
    // final MultipartConfigElement multipartConfigElement = new
    // MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
    // MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
    // 
    // appServlet.setMultipartConfig(multipartConfigElement);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Example 70 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project tutorials by eugenp.

the class MainWebAppInitializer method onStartup.

/**
 * Register and configure all Servlet container components necessary to power the web application.
 */
@Override
public void onStartup(final ServletContext sc) throws ServletException {
    System.out.println("MainWebAppInitializer.onStartup()");
    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("org.baeldung.spring.config");
    // root.getEnvironment().setDefaultProfiles("embedded");
    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));
    // Handles requests into the application
    final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Aggregations

GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)93 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)33 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)32 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)31 Test (org.junit.Test)30 Test (org.junit.jupiter.api.Test)30 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)9 MockServletContext (org.springframework.mock.web.MockServletContext)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)6 WebApplicationContext (org.springframework.web.context.WebApplicationContext)6 Method (java.lang.reflect.Method)5 HttpSession (javax.servlet.http.HttpSession)5 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)5 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)5 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4