当前位置: 首页 > news >正文

如何用iis做网站电子商务网站建设的论文

如何用iis做网站,电子商务网站建设的论文,我赢网提供的高水平网页设计师,公司网站建设好大家好#xff0c;我是烤鸭#xff1a; 今天遇到一个拦截器失效的问题#xff0c;具体看源码分析下。 环境: springboot 2.x spring 5.x 1. 先说下业务场景 需求是对请求进入时和离开时对和线程id绑定#xff0c;用的Threadlocal#xff0c;现在有一个问题#xff0…大家好我是烤鸭 今天遇到一个拦截器失效的问题具体看源码分析下。 环境: springboot 2.x spring 5.x 1.  先说下业务场景 需求是对请求进入时和离开时对和线程id绑定用的Threadlocal现在有一个问题利用拦截器的方式不生效。 2.   拦截器创建的几种方式 2.1 extends WebMvcConfigurationSupport Configuration public class WebMvcAutoConfigurationAdapter extends WebMvcConfigurationSupport {AutowiredMapiHttpRequestInterceptor mapiHttpRequestInterceptor;Overridepublic void addInterceptors(InterceptorRegistry registry) {InterceptorRegistration addInterceptor registry.addInterceptor(mapiHttpRequestInterceptor);// 拦截配置addInterceptor.addPathPatterns(/**);} }Component class MapiHttpRequestInterceptor implements HandlerInterceptor{ } 2.2 implements WebMvcConfigurer Configuration public class WebMvcAutoConfiguration3Adapter implements WebMvcConfigurer {AutowiredMapiHttpRequest3Interceptor mapiHttpRequestInterceptor;Overridepublic void addInterceptors(InterceptorRegistry registry) {InterceptorRegistration addInterceptor registry.addInterceptor(mapiHttpRequestInterceptor);// 拦截配置addInterceptor.addPathPatterns(/**);} }Component class MapiHttpRequest3Interceptor implements HandlerInterceptor{} 先说下结论如果项目中出现了一次 extends WebMvcConfigurationSupport 其他的 extends WebMvcConfigurationSupport 和 implements WebMvcConfigurer 会失效 。 3.   看下源码为啥呢 先看下 WebMvcConfigurationSupport 这个类 addInterceptors 这个方法默认继承的是 DelegatingWebMvcConfiguration这个类就是获取 所有 实现 WebMvcConfigurer 的子类调用他们的方法如果有多个 通过实现 WebMvcConfigurer 创建的拦截器是都可以生效的。 那多个 继承 WebMvcConfigurationSupport  为啥只有一个生效呢答案在这个类WebMvcAutoConfiguration 的 ConditionalOnMissingBean 注解只实例化一个Bean多个继承也只有一个生效。 再看下 addInterceptors 啥时候触发的获取拦截器的时候获取过就不再获取了所以 addInterceptors 在项目启动触发才有效。而 getInterceptors 这个方法是在 handerMapping映射的时候触发的(比如 RequestMappingHandlerMapping、BeanNameUrlHandlerMapping)。 4.   解决方案 针对不同的场景解决方案也不一样我想到的有3个方案。 不继承 WebMvcConfigurationSupport 拦截器全部通过实现 WebMvcConfigurer 接口推荐只继承一次 WebMvcConfigurationSupport ,在这个类管理所有的拦截器(不推荐耦合性太高)针对我的场景我通过 过滤器实现的。注入的代码就不贴了before 和 fater 方法实现了类似拦截器的 preHandle 和 afterCompletion。有一点需要注意的是指定过滤器的排序(默认已经是最高了可以忽略)由于过滤器是链式调用如果想当拦截器用必须指定最先加载还有就是过滤器会拦截静态资源做好对静态资源的放行。 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {if (servletRequest instanceof HttpServletRequest) {HttpServletRequest request (HttpServletRequest)servletRequest;this.before(request);filterChain.doFilter(servletRequest, servletResponse);this.after();} } Bean public FilterRegistrationBean mapiXxxFilterRegister() {FilterRegistrationBean filterRegistrationBean new FilterRegistrationBean();filterRegistrationBean.setOrder(2147483647);filterRegistrationBean.setFilter(this.mapiXxxFilter);filterRegistrationBean.setName(filter-xxx);filterRegistrationBean.addUrlPatterns(new String[]{/*});return filterRegistrationBean; } 这两篇文章也是类似的问题大家也可以看下 https://www.lyscms.info/blog/detail/33A55BEE2FD94E66B40990EA4967D3F7 https://blog.csdn.net/pengdandezhi/article/details/81182701
http://www.yutouwan.com/news/222400/

相关文章:

  • 无锡嘉饰茂建设网站地方新闻门户网站源码
  • 推荐医疗网站建设展示营销型网站
  • 企业网站模板源码免费南通网站开发公司
  • 手机网站淘宝客怎么做wordpress 2.0 下载地址
  • 开源的企业网站管理系统静态网站漏洞
  • 如何提高网站关键词排名wordpress修改教程
  • 留学网站建设方案织梦做的网站打开空白
  • 列举网站建设的SEO策略海南省住房和城乡建设厅网站网上版
  • 新乡网站建设设计广州微网站建设dmz100
  • 常德政务网站app制作定制外包88
  • 回收网站怎么做xampp 搭建wordpress
  • 在那做网站discuz手机版
  • nas搭建wordpress博客网站wordpress产品属性搭配
  • 企业网站建站企业管理咨询公司企业文化
  • 有系统源码可以做网站吗百度信息流代运营
  • 玉泉路做网站安徽省建设工程资源网
  • 公司网站asp源码广州顶正餐饮培训学校
  • 农产品应该建设哪个网站国家反诈中心app下载注册
  • html5 购物网站解决wordpress打开慢的问题
  • 学校网站开发seo白帽优化
  • wordpress获取用户文章游戏交易类网站seo怎么做
  • 网站准确的定位笨笨网站建设专家
  • vps主机访问网站什么网站管理系统好
  • 做班级网站的目的域名注册证书
  • 租服务器发布网站网站建设项目外包网站
  • 个人网站备案备注怎么网站设计
  • 新网站建设运营年计划北京集团 网站建设
  • 深圳做商城网站建设做国外网站什么定位
  • 中国建设银行钓鱼网站熟悉网页设计人机交互实验报告
  • php 网站开发的来源公司网站站建设协议