2

Is it possible to inject an EJB into any class? And who performs the injection - EJB container or the container of the classes that contain EJB annotation?

gicig
  • 334
  • 3
  • 14
  • 1
    does [this](http://stackoverflow.com/questions/12348542/what-does-the-ejbs-annotation-do) help? It basically explains the purpose of `EJB` annotation. – Sabir Khan May 11 '16 at 09:29
  • [The answer](http://stackoverflow.com/questions/4684112/how-do-cdi-and-ejb-compare-interact) by Maxym helped me get the answer to my question. He says "The main idea is that class, where you inject, should be managed by EJB container.". It means that EJB container injects EJBs into classes that have @EJB. – gicig May 11 '16 at 11:11

1 Answers1

3

Here is an extract from Java EE Tutorial:

Dependency injection is the simplest way of obtaining an enterprise bean reference. Clients that run within a Java EE server-managed environment, JavaServer Faces web applications, JAX-RS web services, other enterprise beans, or Java EE application clients, support dependency injection using the javax.ejb.EJB annotation.

Applications that run outside a Java EE server-managed environment, such as Java SE applications, must perform an explicit lookup. JNDI supports a global syntax for identifying Java EE components to simplify this explicit lookup.

Community
  • 1
  • 1
ujulu
  • 3,289
  • 2
  • 11
  • 14