Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

java CDI: @Singleton @Startup @Inject not working implementing an interface

On openLiberty, java 8, Using a class

@Singleton(name = "AppContext")
@Startup
public class A implement B{
...
}


@ApplicationScoped
public class C{

    @Inject
    private A someA;

}

I get a

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type A with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject public someA....

I dont understand why if I dont implement any interface its working but as soon as I add implement B it is not anymore! Didnt find any documentation about that 🙁

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thx!

>Solution :

It looks like you’re declaring a singleton session EJB.

By default, a session bean class which implements no interfaces and doesn’t define any views in another way has a no-interface view and so other classes can inject it directly using its class:

If the bean does not expose any other client views (local, remote, no-interface, 2.x Remote Home, 2.x Local Home, Web Service) and its implements clause is empty, the bean defines a no-interface view.

Spec 4.9.8

However, if a session bean implements an interface then unless you use annotations to explicitly define the bean’s business interfaces, all the interfaces it implements are treated as business interfaces and it doesn’t get a no-interface view. In this case, it can’t be injected directly using its class.

[If business interfaces are not explititly designated and] If the bean class is annotated with the Local annotation, or if the bean class is annotated with neither the Local nor the Remote annotation, all implemented interfaces (excluding the interfaces listed above) are assumed to be local business interfaces of the bean.

Spec 4.9.7

You should either inject the EJB using its interface (i.e. @Inject private B someB;) or explicitly declare that the EJB has a no-interface view by adding @LocalBean to A. (In this case you may also want to use @Local to say which other implemented interfaces are business interfaces).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading