A Java EE server has different containers like EJB or Web Container:
I found however different information on how the CDI component is integrated. In the litarature some speak of a CDI container ("The CDI container manages all beans inside the scope automatically for you") but others define it as contextual services provided by Java EE containers. Here on stackoverflow there is even a tag called "IOC-Container". So if it is a container is that container part/inside of the EJB/Web container?
So if I draw a picture of a Java EE server with its components and containers (like the above illustration) how does CDI fits in there? Does it get its own container "rectangle" or is it part of some EJB/Web container? How would you draw it in an architectural design and how would you explain/describe it?
A Java EE server provides EJB and web containers. Enterprise JavaBeans (EJB) container: Manages the execution of enterprise beans for Java EE applications. Enterprise beans and their container run on the Java EE server.
They are CDI, EJB3 and JSF Managed Beans. CDI is the new kid on the block. CDI beans feature dependency injection , scoping and an event bus . CDI beans are the most flexible with respect to injection and scoping. The event bus is very lightweight and very well suited for even the simplest of web applications.
The main difference between the web containers and application server is that most web containers such as Apache Tomcat implements only basic JSR like Servlet, JSP, JSTL wheres Application servers implements the entire Java EE Specification.
Web container: Manages the execution of JSP page and servlet components for Java EE applications. Web components and their. container run on the Java EE server. Application client container: Manages the execution of application client components. Application clients and their container run on the client.
CDI has a separate container. In your picture it would be most likely another separate rectangle on EE server side. Talking about EE environment, CDI is provided by the EE container (usually the RI - Weld) and as such the container will start it for you upon (first) application deployment.
That being said, CDI container is one per EE server. Even if you deploy several WAR applications all of which use CDI, there will still be one CDI container. Note that in SE environment (Weld SE allows you to use CDI in SE env.), you can have several such containers if you so wish.
As for integration with other EE stuff like EJB and JSF. They for instance allow you to use @Stateless
or @ViewScoped
which are CDI based features. So they have to integrate with CDI "somehow". Now this magic is done inside the EE container, usually via provider's (Weld) SPI. For instance the container is responsible for handling EJB beans and then handing them over (through SPI) to Weld which can then take them over as CDI beans allowing you to @Inject
into @Stateless
beans. Obviously the above is simplification of what actually happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With