#Spring Boot request scope service injected inside singleton service

1 messages · Page 1 of 1 (latest)

light egret
#

Hi,
First, a basic explanation about my application:
It's a SpringBoot application which host a discord bot (with the JDA Api). To do it, I have a singleton CommandLineRunner which inject some service and repositories.
At the same time, my application host a web server (a REST Api) so the bot can be customised and interacted by a website I build in parallel.

The problem is: all the services & repositories the website need use the @RequestScope annotation. But the CommandLineRunner is a singleton. How can my singleton inject the RequestScoped beans so ?

(sry for approximate english)

mental jasperBOT
#

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

mental jasperBOT
#

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.

light egret
#

The best thing I could get is that Spring thinks the singleton instances represent the same request so all the request scope beans stay the same for singletons

dusk birch
#

Why do the classes for the website require @RequestScope

#

You can just use singletons inside your web app 🙂