Using Dependency Injection in Java EE 5.0

Using Dependency Injection in Java EE 5.0

The Benefits and Limitations of Dependency Injection

Benefits

Dependency injection makes resources and services easier to use because you don't have to deal with the complexities of JNDI. You don't have to write hundreds of lines of code or write service locator patterns.

Java EE supports dependency injection either via XML or annotation, so use annotation only when it makes sense. Annotation can make your code more readable and concise--not to mention make your life easier--but it can also cause maintenance problems, since the method requires that resource references are hard-wired into the application code. The good news is that you can override annotations using XML elements.

Limitations

Because Java EE 5.0 supports dependency injection with managed classes, you can't use dependency injection from helper classes. And you must still use JNDI if you want to use resources or services from a helper class.

Conclusion

Dependency injection will greatly simplify the complexities of JNDI and make it easier to develop enterprise applications. See for yourself how it makes using resources and services easier: try it out in Oracle Application Server 10g 10.1.3 and JBoss 4.0.x, both of which offer early support for EJB 3.0 and dependency injection in the EJB container.

Resources

  • OTN EJB 3.0 Resource Center
  • Java EE 5.0 Early Release draft specification (JSR 244)
  • Common Metadata annotations for Java Platform Proposed Final Draft specification (JSR 250)
  • EJB 3.0 Public Draft specification (JSR 220)
  • Java API for XML web services 2.0 Proposed Final Draft specification (JSR 224)

Debu Panda is a Senior Principal Product Manager of the Oracle Application Server development team.


Return to ONJava.com.

Prev  [1] [2] [3] [4] [5] 

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JavaBeans > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction