@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("com.sms.config"); // 加入logback监听器 servletContext.addListener(new LogbackConfigListener()); // 加入spring监听器 servletContext.addListener(new ContextLoaderListener(context)); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); // 加入spring mvc配置 ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring-mvc", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); // 加入OpenEntityManagerInViewFilter FilterRegistration.Dynamic openEntityManagerInViewFilter = servletContext.addFilter( "openEntityManagerInViewFilter", OpenEntityManagerInViewFilter.class); openEntityManagerInViewFilter.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); // 加入security过滤器 FilterRegistration.Dynamic securityFilterChain = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); securityFilterChain.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); // 加入Spring编码过滤器 CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("characterEncodingFilter", characterEncodingFilter); encodingFilter.addMappingForUrlPatterns(dispatcherTypes, true, "/"); }
private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("pl.opencvtest.WebConfig"); return context; }
private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation(APP_PKG); return context; }
private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("com.pluralsight.WebConfig"); return context; }
private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); // Look for configuration in /src/main/java/FreeMarkerTutorials/config/ context.setConfigLocation("FreeMarkerTutorials.config"); return context; }