[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]WebApplicationInitializer动态增加Filter,用java代码实现web.xml中的filter配置

上一篇:[备忘]jQuery UI Layout
下一篇:[备忘]javascript获取同域名的最顶层窗口

添加日期:2017/7/20 7:57:28 快速返回   返回列表 阅读4064次
继承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");
        
        
    }

}

 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved