Using Dependency Injection in Java EE 5.0
Subject:   So what's new ?
Date:   2006-01-11 00:28:28
From:   GerritCap
Response to: So what's new ?

A few remarks:

  1. Often the mnemonics J2EE and EJB are used interchangably. But I think that J2EE stand for enterprise computing as a step in the evolution of stand alone apps -> client/server -> 3-tier apps. A more flexible way of organising your code. EJB is an implementation of that flexible organisation and delivered by tools like WebSphere, JBoss, WebLogic, Geronimo, ... So where you talk about a J2EE container you should really mention an EJB container.

  2. If I understand your article and rely correctly using field injection you either specify the name of the resource or the EJB container derives the name from its declaration. And binding the resource is done by the EJB container based upon that name.

    Well to me this is conceptually exactly the same as requesting the EJB container for a bean with a certain name although you don't program it that way.

    Again if I understand it correctly, setter injection isn't basically that different. The EJB container again sets the resource based upon the name of the setter.

    So where is the conceptual difference of looking up a bean by its name or the EJB container binding a resource to your objects based upon your name? This is a very limiting IoC strategy, like having inheritance in a OO language without polymorphism. The basics are there but you don't go all the way. Example what if you have 2 DAO's that programmatically use the same name for a data source resource but in a certain setup they would have to use 2 different datasources.

    In a conceptually complete IoC implementation (like Spring) you define a DAO object, you define a datasource and you link (or wire) them together. If tomorrow you need a different datasource for that bean then you wire another datasource to it indepedant of the fact of your original datasource still being used (or wired to) another dao.

  3. Talking about proprietary or portability:
    • Using Spring all of your java code never has to reference any Spring related class or whatsoever. Every object can be a POJO. You can use Spring to set a specific LayoutManager in a JPanel. Using EJB if you want to make an object persistent then it has to be a subclass of javax.ejb.EntityBean.

    • Spring configuration is done using an XML file, if for some reason you don't like spring anymore then you can do the wiring hard coded for example or you can interpret the same XML structure and do the wiring based upon your own interpretation. Or if there is a particular part you don't like about Spring then use it's source code and change it the way you like it. In a project I used to work on there was one particular thing we didn't like about EJB but a) we could not change the EJB container and b) all of our classes where already dependant to the javax.ejb hierarchy so we had 2 choices: delete all code and start all over without EJB or shut up and put up with the EJB situation.

    • Ever tried to migrate an EJB project from WebSphere to WebLogic or vice versa ? In every implementation of an EJB container there are some "additions" the are completely propriatary. Once I tried using a java webstart app and using the "original" java runtime environment to connect to a WebSphere EJB Session bean. You needed a IBM JRE including some IBM dll's on windows or a "patched" Sun JRE for the reaqson of having some portability between ibm's corba and ibm's rmi implementation usin in ejb's. Go figure. What are all these "Controls" you use in a WebLogic environment, you think they are portable to WebSphere ??? Why is there an org.jboss.ejb.EnterpriseContext ???

      Get real: every commercial EJB implementation makes money on you using their implementation so they will add some "features" only available on their platform (which usually makes your life easier in certain situations I agree) but once you use these features typically the cost of migrating to another EJB implementation is enourmous compared to the promise of "portability of EJB's". I know of a highly payed (and thus costly) consultant of company XYZ make a lot of money doing nothing but migrating customers to the XYZ EJB platform.

  4. I agree: Spring is not touted as an alternative to J2EE but as an alternative to EJB and definitly not supposed to be used within a EJB container. Read the book of Rod Johnson & Juergen Hoeller (the 2 most important persons behind Spring in my humble opinion) called "J2EE development without EJB". Can it be more clear?
  5. And basically Spring is not a framework, it are a number of different frameworks

    1. Spring core: used to wire plain POJO's implementing the full conceptuial meaning of IoC and allowing you to set properties of objects

    2. AOP implementation: add aspects of your logic to your code wihtout implementing them. Typical example is transaction management.

    3. JDBC support: using Spring's JdbcTemplates or use O/R tools like hibernate but not restricted to hibernate

    4. MVC web framework: going that one important step futher than struts. But allowing you to use struts, struts tiles and/or java server faces.

    5. Integration with EJB: yes you can integrate it with EJB for those who can't avoid it I guess

    6. JMS, Mail, JMX, job scheduling,...


1 to 1 of 1
1 to 1 of 1