标签:分享 xml配置 services http gis src service 初始化 date
在正常的Spring MVC 框架中使用Filter时需要在XML文件中配置
<filter> <filter-name>xxxFilter</filter-name> <filter-class>xx.xx.xx.xx.xxxFilter</filter-class> </filter> <filter-mapping> <filter-name>xxxFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
但是在Spring boot 中抛弃了XML配置,所以要在启动主函数中添加
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
WeChatFilter weChatFilter = new WeChatFilter();
registrationBean.setFilter(weChatFilter);
List<String> urlPatterns = new ArrayList<String>();
urlPatterns.add("/validate/*");
registrationBean.setUrlPatterns(urlPatterns);
return registrationBean;
}
补充:
如果想要在Filter中执行Services方法,要在初始化Filter中执行下图方法(因为Filter执行顺序提前与Services)
标签:分享 xml配置 services http gis src service 初始化 date
原文地址:http://www.cnblogs.com/yibin-xie/p/6589599.html