Support @RequestScoped beans in command line mode
See original GitHub issueDescription Having
@RequestScoped
public class MyJPAService {
}
And the main class for a command line application:
@QuarkusMain
public class MainApplication implements QuarkusApplication {
@Inject
MyJPAService service;
public static void main(String[] args) {
Quarkus.run(MainApplication.class, args);
}
@Override
public int run(String... args) throws Exception {
System.out.println("Instance: " + service);
return 0;
}
}
When I run mvn quarkus:dev
, I get the following exception:
2020-04-22 13:29:50,255 ERROR [io.qua.run.Application] (Quarkus Main Thread) Error running Quarkus application: javax.enterprise.context.ContextNotActiveException: interface javax.enterprise.context.RequestScoped
A workaround is to call Arc.container().requestContext().activate();
in the MainApplication#run
method (and deactivate when it’s done).
Implementation ideas
Change the core implementation that calls my Main method to initialize the Arc container if a @RequestScoped
class is used.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Introducing Command Mode - Quarkus
In Quarkus 1.4 command mode lets you write apps that run without an ... If you would like to access request scoped beans...
Read more >Spring - Request scoped bean from object pool - Stack Overflow
Implement a HandlerInterceptor and inject it with a request scoped bean. When preHandle is called, setup the bean with the correct value.
Read more >9 Using Contexts and Dependency Injection for the Java EE ...
This example defines the scope of the Accountant bean class to be @RequestScoped . The Accountant class in this example is qualified by...
Read more >A Command Line Application with Quarkus - Adam Bien
Command mode already ships with quarkus runtime, there are no additional ... Therefore scopes like e.g. @RequestScoped are not available.
Read more >Context and Dependency Injection beans :: Open Liberty Docs
Contexts, which help you bind the lifecycle and interactions of stateful ... beans.xml file or a beans.xml file with the bean-discovery-mode="all" attribute ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nope. We should either activate it automatically or encourage users to use
@ActivateRequestContext
.I believe that the intention is to support
@RequestScoped
beans during “quarkus command execution”. And the request context is not necessarlly bound to an HTTP request. There are few exceptions in the spec and we have few more in Quarkus. In this case, the command execution is a “request”.Yes,
@ActivateRequestContext
should work.