Spring:如何将HttpServletRequest注入请求范围的bean? [英] Spring: how do I inject an HttpServletRequest into a request-scoped bean?

查看:368
本文介绍了Spring:如何将HttpServletRequest注入请求范围的bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 request-scoped bean

我已成功设置它,因此每次创建一次bean请求。现在,它需要访问HttpServletRequest对象。

I've successfully set it up so the bean is created once per request. Now, it needs to access the HttpServletRequest object.

由于每个请求创建一次bean,我认为容器可以很容易地在我的bean中注入请求对象。我该怎么做?

Since the bean is created once per request, I figure the container can easily inject the request object in my bean. How can I do that ?

推荐答案

请求范围的bean可以与请求对象一起自动装配。

Request-scoped beans can be autowired with the request object.

private @Autowired HttpServletRequest request;

这篇关于Spring:如何将HttpServletRequest注入请求范围的bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆