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

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

问题描述

我正在尝试建立一个 Spring 中的请求范围 bean.

I'm trying to set up a request-scoped bean in Spring.

我已成功设置,因此每个请求都会创建一次 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天全站免登陆