在Spring Security 4中获取HttpServletRequest,HttpServletResponse

时间:2015-07-14 12:25:13

标签: spring security servlets request response

我尝试过注入HttpRequest,HttpResponse。

尝试

@Bean
public RequestContextListener requestContextListener(){
   return new RequestContextListener();
}

@Controller("/test")
 public class Test {
    public String callback() {
        SecurityContextHolder.getContext().setAuthentication(auth);
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        HttpServletResponse response = attributes.getResponse();
    }
}

没什么,我总是收到一个空物。

1 个答案:

答案 0 :(得分:0)

这是Spring的方法:

select X, count(distinct Y)
from TBL
group by X