Subproject dependency injection . jar

Asked

Viewed 98 times

0

I have an app EJB who owns a lib jar as a dependency built for code reuse. My . jar has a class that has been annotated with @RequestScoped, and I need to retrieve it on my ejb.

I’m using the following line, someone knows why it doesn’t work?

MinhaClasse o = CDI.current().select(MinhaClasse .class).get();
return o.getNome();

Error code:

  Caused by: org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type: class br.com.meuprojeto.jpa.MinhaClasse; Qualifiers: []

1 answer

0


The Minhaclasse class is not eligible for the CDI.

  1. Make sure you’re using CDI @Requestscoped (javax.enterprise.context).
  2. Use @Inject to perform the injection. How an EJB is managed by the container, the bean will be injected normally.
  3. Make sure your JAR has the Beans.xml file in the META-INF folder.

If none of this solves, you can still create a method annotated with @Produces that returns an instance of the Minhaclasse class. Since the method parameter you can receive what is necessary for creating the instance (the received items by parameter have to be CDI-eligible).

  • Your answer fixed My JAR did not have xml Beans.xml .

  • @OK, I’m glad you helped :). Please mark the answer as the solution and if possible vote for it. This will help me to grow here in stackoverflow. :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.