diff --git a/src/main/java/com/monkeyk/sos/config/ServletInitializer.java b/src/main/java/com/monkeyk/sos/config/ServletInitializer.java new file mode 100644 index 0000000..f73512f --- /dev/null +++ b/src/main/java/com/monkeyk/sos/config/ServletInitializer.java @@ -0,0 +1,67 @@ +package com.monkeyk.sos.config; + +import com.monkeyk.sos.web.filter.CharacterEncodingIPFilter; +import com.opensymphony.sitemesh.webapp.SiteMeshFilter; +import org.springframework.web.filter.DelegatingFilterProxy; +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; +import org.springframework.web.util.Log4jConfigListener; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +/** + * 2016/4/3 + *
+ * Config DispatchServlet + * + * Replace web.xml + * + * @author Shengzhao Li + */ +public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + + + @Override + protected Class>[] getRootConfigClasses() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + protected Class>[] getServletConfigClasses() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + protected String[] getServletMappings() { + return new String[]{"/"}; + } + + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + super.onStartup(servletContext); + +// servletContext.setAttribute("webAppRootKey", "spring-oauth-server"); + servletContext.setInitParameter("webAppRootKey", "spring-oauth-server"); + servletContext.setInitParameter("contextConfigLocation", "classpath:spring/*.xml"); + servletContext.setInitParameter("log4jConfigLocation", "/WEB-INF/log4j.xml"); + + //Add Filters + + CharacterEncodingIPFilter characterEncodingIPFilter = new CharacterEncodingIPFilter(); + characterEncodingIPFilter.setEncoding("UTF-8"); + characterEncodingIPFilter.setForceEncoding(true); + servletContext.addFilter("encodingFilter", characterEncodingIPFilter).addMappingForUrlPatterns(null, false, "/*"); + + DelegatingFilterProxy securityFilter = new DelegatingFilterProxy("springSecurityFilterChain"); + servletContext.addFilter("springSecurityFilterChain", securityFilter).addMappingForUrlPatterns(null, false, "/*"); + + SiteMeshFilter siteMeshFilter = new SiteMeshFilter(); + servletContext.addFilter("sitemesh", siteMeshFilter).addMappingForUrlPatterns(null, false, "/*"); + + //Add Listeners + + servletContext.addListener(Log4jConfigListener.class); + + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml.old similarity index 100% rename from src/main/webapp/WEB-INF/web.xml rename to src/main/webapp/WEB-INF/web.xml.old