我在ssm+shiro的中 spring test测试想要注入httpservletRequest 但是不知道怎么注入
@Autowired 也试过了
我们项目我看了看是在fileter类中封装到model类里
public class CommonUtils {
private CommonUtils(){
}
private static ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<HttpServletRequest>();
public class CommonFilter implements Filter {
private FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
CommonUtils.setRequest((HttpServletRequest) servletRequest);
filterChain.doFilter(servletRequest,servletResponse);
}
public void destroy() {
CommonUtils.removeCommon();
}
}
获取的时候,直接用CommonUtils的get方法获取,你可以试一试
在方法的入参中添加httpServletRequest 就可以获取request了