继承WebApplicationInitializer这个类即可,然后写代码添加Filter,listener即可。
貌似是在web.xml之后执行吧?因为xml中已经写了某个filter的话,这里的addFilter方法会返回null。
可以用@Order(100)来指定加载顺序,不指定默认为最小,即最先执行 不过这个顺序,不过是多个WebApplicationInitializer之间的执行顺序 WebApplicationInitializer和xml中定义的先后顺序怎么搞,不晓得~~
package com.xxxx.config;
import javax.servlet.ServletContext; import javax.servlet.ServletException;
import org.springframework.web.WebApplicationInitializer;
/** * 启动时自动调用此类. * */ public class MyAppInitializer implements WebApplicationInitializer {
@Override public void onStartup(ServletContext servletContext) throws ServletException { //单点退出Filter javax.servlet.FilterRegistration.Dynamic filter = servletContext.addFilter("CAS Single Sign Out Filter", org.jasig.cas.client.session.SingleSignOutFilter.class); if(filter==null){ System.out.println("exist,skip it"); }else{ filter.addMappingForUrlPatterns(null, false, "/*"); } //单点退出Listener servletContext.addListener(org.jasig.cas.client.session.SingleSignOutHttpSessionListener.class); // 权限filter javax.servlet.FilterRegistration.Dynamic shiroFilter = servletContext.addFilter("shiroFilter", org.springframework.web.filter.DelegatingFilterProxy.class); shiroFilter.addMappingForUrlPatterns(null, false, "/*"); shiroFilter.setInitParameter("targetFilterLifecycle", "true"); }
}
|