41 changed files with 194 additions and 55 deletions
@ -1,45 +1,45 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.commons.tools.aspect; |
|||
|
|||
import com.epmet.commons.tools.constant.ThreadLocalConstant; |
|||
import com.epmet.commons.tools.dto.form.LoginUserInfoResultDTO; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 每次请求,清理ThreadLocal线程中的变量 |
|||
* @Author wxz |
|||
* @Description |
|||
* @Date 2020/4/23 16:16 |
|||
**/ |
|||
@Aspect |
|||
@Component |
|||
@Order(1) |
|||
public class ThreadLocalInitAspect { |
|||
|
|||
private static final Logger log = LoggerFactory.getLogger(ThreadLocalInitAspect.class); |
|||
|
|||
@Before(value = "execution(* com.epmet.controller.*Controller*.*(..)) ") |
|||
public void before(JoinPoint point) throws Throwable { |
|||
// 清理权限过滤中的变量残留
|
|||
try { |
|||
ThreadLocalConstant.sqlFilter.remove(); |
|||
ThreadLocalConstant.requirePermissionTl.remove(); |
|||
} catch (Exception e) { |
|||
log.error("清理sqlFilter缓存失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
} |
|||
} |
|||
///**
|
|||
// * Copyright (c) 2018 人人开源 All rights reserved.
|
|||
// * <p>
|
|||
// * https://www.renren.io
|
|||
// * <p>
|
|||
// * 版权所有,侵权必究!
|
|||
// */
|
|||
//
|
|||
//package com.epmet.commons.tools.aspect;
|
|||
//
|
|||
//import com.epmet.commons.tools.constant.ThreadLocalConstant;
|
|||
//import com.epmet.commons.tools.dto.form.LoginUserInfoResultDTO;
|
|||
//import com.epmet.commons.tools.exception.ExceptionUtils;
|
|||
//import org.aspectj.lang.JoinPoint;
|
|||
//import org.aspectj.lang.annotation.Aspect;
|
|||
//import org.aspectj.lang.annotation.Before;
|
|||
//import org.slf4j.Logger;
|
|||
//import org.slf4j.LoggerFactory;
|
|||
//import org.springframework.core.annotation.Order;
|
|||
//import org.springframework.stereotype.Component;
|
|||
//
|
|||
///**
|
|||
// * 每次请求,清理ThreadLocal线程中的变量(已废弃,改用GlobalFilter)
|
|||
// * @Author wxz
|
|||
// * @Description
|
|||
// * @Date 2020/4/23 16:16
|
|||
// **/
|
|||
//@Aspect
|
|||
//@Component
|
|||
//@Order(1)
|
|||
//public class ThreadLocalInitAspect {
|
|||
//
|
|||
// private static final Logger log = LoggerFactory.getLogger(ThreadLocalInitAspect.class);
|
|||
//
|
|||
// @Before(value = "execution(* com.epmet.controller.*Controller*.*(..)) ")
|
|||
// public void before(JoinPoint point) throws Throwable {
|
|||
// // 清理权限过滤中的变量残留
|
|||
// try {
|
|||
// ThreadLocalConstant.sqlFilter.remove();
|
|||
// ThreadLocalConstant.requirePermissionTl.remove();
|
|||
// } catch (Exception e) {
|
|||
// log.error("清理sqlFilter缓存失败:{}", ExceptionUtils.getErrorStackTrace(e));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
@ -0,0 +1,30 @@ |
|||
package com.epmet.commons.tools.filter; |
|||
|
|||
import com.epmet.commons.tools.constant.ThreadLocalConstant; |
|||
|
|||
import javax.servlet.*; |
|||
import javax.servlet.annotation.WebFilter; |
|||
import java.io.IOException; |
|||
|
|||
/** |
|||
* @Description 全局过滤器,可在请求结束的时候清除线程变量残留 |
|||
* @author wxz |
|||
* @date 2021.07.19 10:19:24 |
|||
*/ |
|||
@WebFilter(value = "/*") |
|||
public class GlobalFilter implements Filter { |
|||
|
|||
@Override |
|||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
|||
try { |
|||
filterChain.doFilter(servletRequest, servletResponse); |
|||
} catch (Throwable e) { |
|||
throw e; |
|||
} finally { |
|||
// 清除线程变量残留
|
|||
ThreadLocalConstant.sqlFilter.remove(); |
|||
ThreadLocalConstant.requirePermissionTl.remove(); |
|||
ThreadLocalConstant.requestParam.remove(); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue