Skip to content

Rest client Inject Mock in unit test - RequestScoped #45006

Answered by geoand
RF-Flores asked this question in Q&A
Discussion options

You must be logged in to vote

There will be many requests sent concurrently, I don't wish to have to guarantee thread safety using ApplicationScopped, I would rather leverage RequestScope to do that for me.

Thread-safery is orthogonal to whether the client is request scoped or not. And in all reality @RequestScoped is tied to the current request being served, so it something that needs to be active (for example automatically by Quarkus when an HTTP request is being served or manually by starting the scope) before any such bean is used.
Actually, I would very much recommend not using request scoped for the REST Client as you are going to be creating a very large overhead for each request.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@geoand
Comment options

geoand Dec 9, 2024
Collaborator

@RF-Flores
Comment options

@geoand
Comment options

geoand Dec 9, 2024
Collaborator

Answer selected by RF-Flores
@RF-Flores
Comment options

@geoand
Comment options

geoand Dec 9, 2024
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants