0

I'm developing a JEE Web Application (no Spring), and I'm getting this exception.

class org.jboss.weld.context.ContextNotActiveException,message=WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped

From a JSF Backing bean I'm calling a method in an aplication scoped class, and this method executes asynchronously some

CompletableFuture.runAsync(()-> methodInTransactionGoingToRepository()}

However I'm getting that exception because it runs with no Request Context. I know I could isolate these calls in Rest APi and make some Async Posts, and it would work. But the application is small, and not suitable to have other services.

How can I solve this. Is there a way to activate a Request Scope before calling methodInTransactionGoingToRepository();

Thanks in Advance.

rui
  • 79
  • 2
  • 7
  • You _can't_ "solve this". You run `runAsync`, i.e. in a different thread, your context is lost. Run in the same thread if you want it to work. – Eugene Nov 14 '20 at 13:29
  • So, I can't execute a method asynchronously in JEE7. No workaround?, i.e, other than using rest api or JMS? – rui Nov 14 '20 at 15:01
  • Hi, Thanks for the insight BalusC. Actually I've alreadu tried with EJB asynchronous methods. `class Backingbean { @EJB private MyService }` And MyService annotated with `@Local @Singleton (or @Stateless)`, with the asynchronous method I want to call from the Backing bean, and the same exception is thrown: **No active contexts for scope type javax.enterprise.context.RequestScoped** – rui Nov 15 '20 at 17:13
  • I'm searching for it. But what I exactly want is to run assynchronously a method inside a CDI Bean( a method to process a validation that needs to go to read and write into a repository). The method is now acceptin one argument (a Long id) – rui Nov 16 '20 at 00:41

0 Answers0