protected void onStartup ( ServletContext servletContext , Class < ? > appConfig , int maxFileSize ) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext ( ) ; rootContext . setAllowBeanDefinitionOverriding ( false ) ; rootContext . register ( appConfig ) ; // Manage the lifecycle of the root application context servletContext . addListener ( new ContextLoaderListener ( rootContext ) ) ; // Register and map the dispatcher servlet DispatcherServlet dispatcherServlet = new DispatcherServlet ( rootContext ) ; dispatcherServlet . setDispatchOptionsRequest ( true ) ; // instead of throwing a 404 when a handler is not found allow for custom handling dispatcherServlet . setThrowExceptionIfNoHandlerFound ( true ) ; ServletRegistration . Dynamic dispatcherServletRegistration = servletContext . addServlet ( "dispatcher" , dispatcherServlet ) ; if ( dispatcherServletRegistration == null ) { LOG . warn ( "ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'" ) ; } else { final long maxSize = ( long ) maxFileSize * MB ; dispatcherServletRegistration . addMapping ( "/" ) ; dispatcherServletRegistration . setMultipartConfig ( new MultipartConfigElement ( null , maxSize , maxSize , FILE_SIZE_THRESHOLD ) ) ; dispatcherServletRegistration . setAsyncSupported ( true ) ; } // add filters Dynamic browserDetectionFiler = servletContext . addFilter ( "browserDetectionFilter" , BrowserDetectionFilter . class ) ; browserDetectionFiler . setAsyncSupported ( true ) ; browserDetectionFiler . addMappingForUrlPatterns ( EnumSet . of ( DispatcherType . REQUEST , DispatcherType . ASYNC ) , false , "*" ) ; Dynamic etagFilter = servletContext . addFilter ( "etagFilter" , ShallowEtagHeaderFilter . class ) ; etagFilter . setAsyncSupported ( true ) ; etagFilter . addMappingForServletNames ( EnumSet . of ( DispatcherType . REQUEST , DispatcherType . ASYNC ) , true , "dispatcher" ) ; // enable use of request scoped beans in FrontController servletContext . addListener ( new RequestContextListener ( ) ) ; servletContext . addListener ( HttpSessionEventPublisher . class ) ; }
A Molgenis common web application initializer