Java Champion / JavaOne Rockstar Adam Bien ( is a self-employed consultant, lecturer, software architect, developer, and author in the enterprise Java sector. He is also the author of several books and articles on Java and Java EE technology, as well as distributed Java programming. adam has posted 59 posts at DZone. View Full User Profile

CDI With Or Without EJB 3.1

  • submit to reddit

Java EE 6 comes with EJB 3.1 and CDI. You could work exclusively with EJB 3.1 or CDI, but you will not end up with the simplest possible solution. CDI comes with typesafe and scalable (=start easy, but sky is the limit) DI, events, decorators and "glue" logic.

CDI, however, is missing some EJB 3.1 features:

  1. Timers
  2. Asynchronous, transactional execution with Future support
  3. Pooling: important for throttling and prevention of denial of service attacks
  4. Monitoring - all EJBs are exposed via JMX and can be so monitored with JConsole
  5. Declarative, "Convention Over Configuration" transactions. Without EJB 3 you will end up in a considerable bloat

EJB 3.1 and CDI are both part of Java EE 6. The "KISSiest" thing you can do is to deploy a EJB 3.1 boundary and use e.g. CDI behinds behind.

You could also implement all aspects (transactions, jmx, throttling) by your own - but this would introduce additional complexity to your project (and: don't re-invent the wheel).


Published at DZone with permission of its author, adam bien.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Gabor Farkas replied on Wed, 2010/09/15 - 4:02am


adam bien replied on Wed, 2010/09/15 - 7:58am in response to: Gabor Farkas

Weld is a CDI implementation, and it is a subset of Seam.

Gabor Farkas replied on Wed, 2010/09/15 - 8:07am

I meant, if you want to use the ease of CDI with the services of EJB, you can use Seam. Seam 3 will also be EE 6 compliant.

adam bien replied on Wed, 2010/09/15 - 8:44am in response to: Gabor Farkas

Yes. Seam 3 would be also an option. With "vanilla" Java EE 6 (what I am mostly using) EJB 3.1. are the easiest possible choice. thanks! adam

samuel mansoor replied on Wed, 2010/09/15 - 9:50am

I have one question how does Spring IoC differ from EJB CDI. I have not used EJB 3.1 yet and I am a big fan of IoC with spring.

adam bien replied on Wed, 2010/09/15 - 12:11pm in response to: samuel mansoor

Spring IoC is more powerful, than EJB 3.0 and 3.1, but comparable to CDI. CDI uses and implements the JSR-330, a spec led by Bob Lee and Rod Johnson.

King Sam replied on Fri, 2012/02/24 - 9:23am

Hello Adam, i want to know it will be a second edition of your book
in Real World Java EE Patterns - Rethinking Best Practice where explain the JEE 6 Best Practices ?.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.