我已将以下类定义为Bean:
public class RequestInfo {
private String userAgent;
private String header1;
private String header2;
}
我在过滤器中创建它:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain){
RequestInfo request = new RequestInfo();
//populate the request fields by taking it from headers
}
然后我希望能够在我的rest控制器中简单地执行以下操作:
@RestController
public class MyController{
@Autowired
private RequestInfo requestInfo; //it contains the infos
这可能吗?该bean应该位于当前的REST请求中,并在控制器输出响应的那一刻消失。