I have a bean with @RequestScope
in it, and when I inject it in one of my Singletons, it is injected as a singleton and not as a request scope. However, if I change the @RequestScope
to @Scope( value = "request", scopeName = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
, Spring creates the bean as request scope and injects them to the singleton correctly.
I read the documentation of Spring regarding this:
The JSR-330 default scope is like Spring’s prototype. However, in order to keep it consistent with Spring’s general defaults, a JSR-330 bean declared in the Spring container is a singleton by default. In order to use a scope other than singleton, you should use Spring’s @Scope annotation. javax.inject also provides a @Scope annotation. Nevertheless, this one is only intended to be used for creating your own annotations.
Does this mean also that @RequestScoped
is really being ignored by Spring? Is there any Provider/Resolver that resolves this issue with Spring? As much as possible I want to use the @RequestScoped
annotation instead of @Scope
annotation of spring as we are required to use JSR annotations only