#How Spring beans lifecycle works for request

1 messages · Page 1 of 1 (latest)

exotic flint
#

Hi, I'm using Spring Boot to construct a Rest API and I wonder:
If Spring construct my Services as singleton, how could it inject a HttpServletRequest each time a new request is incoming ?

thin eagleBOT
#

<@&1004656351647117403> please have a look, thanks.

thin eagleBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

midnight otter
#

That doesn't sound thread safe

#

Unless you're doing some locking

#

Could you explain your scenario a bit more?

exotic flint
#

I would like to read the Authorization header of the request to identify the logged user

#

My idea is to have a "UserService" which have a "getCurrentUser()" who identity the user depending if the header

#

With a Bearer token or an API key as example

midnight otter
#

Wouldn't it make more sense to make the UserService request scoped

exotic flint
#

But if only the UserService is request scoped, how to know which instance will be passed for instancing other service

#

If a have, as example, a MessageService, which need the UserService to know who is sending message, how should I do ?

Or putting every service in request scoped mode is the best solution ?

midnight otter
#

Either that or make the methods you call accept an object from which you can deduce the user (or the User itself even)

exotic flint
#

Alright :(
And what is the purpose of the proxyMode for request scopped beans ?