I did some experimentation with Quarkus and I am having difficulties understanding how @RequestScoped works. Coming from Spring, I would be expecting that the following code should not work and throw an Exception:
@ApplicationScoped
public class AppLifecycleBean {
@Inject
MyBean myBean;
void onStart(@Observes StartupEvent ev) {
myBean.doSomething();
}
}
@RequestScoped
public class MyBean {
public void doSomething() {
System.out.println("Hello!");
}
}
The request scoped bean is correctly injected as a proxy. But calling a method on the proxy even when there is no request available seems to work just fine?
@RequestScopedare documented? I did not explicitely find something in the Quarkus documentation (except the one you already mentioned). I also discovered myself that@Scheduledmethod also seems to work with@RequestScoped.@RequestScopedbeans [almost] anywhere. (Putting the word "thread" into quotes, because I'm not talking aboutjava.lang.Thread, hope you see what I mean by that.)@ApplicationScopedand@RequestScoped), the thing that is injected is a client proxy, which obtains the correct "current" instance on each method call.