Article:
  Using Dependency Injection in Java EE 5.0
Subject:   So what's new ?
Date:   2006-01-05 13:12:24
From:   DebaPanda
Response to: So what's new ?

But then the article is missing one element: where do you define the resource ? E.g. where in the new J2EE do you define the real class of which the resource is going to be a runtime instance of? Here is what I've in the article:


To use a field injection, simply define a field and annotate it to be a resource reference. If you don't define the resource's name and type, the container will derive this information from the field's name and type.


You must have a resource e.g. DataSource configured in the data-source. Here is what I've in the article "In this example, a DataSource called AdventureDB should be available; if not, the container will throw an exception"


I do not have any thing against Spring. I agree it has some demerits against containers like Spring but makes your code and configuration portable across any Java EE container. Spring configuration being proprietary is not portable and you have to stick with Spring.


Setter injection is also supported with Java EE. If you are an XML fan you use XML instead of annotations as I described in the article. Also note that XML overrides annotation so you change your resource being injected.


Anyway I don't think Spring is being touted as an alternative to Java EE, Spring is touted as a framework to be used with an Java EE container


-Debu


Full Threads Newest First

Showing messages 1 through 4 of 4.

  • So what's new ?
    2006-01-06 03:38:56  DavideBaroncelli [View]

    I do not have any thing against Spring. I agree it has some demerits against containers like Spring but makes your code and configuration portable across any Java EE container. Spring configuration being proprietary is not portable and you have to stick with Spring.

    Uhm. My application runs well on Tomcat, WebSphere and WebLogic, and the only configuration files I have to change when I put it on one server or the other are specific to the implementation of the particular "standard" server: my Spring configuration remains untouched, and Spring actively shields me from part of those platform-specific configuration changes. So, what is the point of talking about the "platform dependence" of a Spring configuration? I use oscache as my caching solution, and so I do rely on a oscache.properties file: this does not make my app less portable. Portability is about different things: portability is about being able to run an APP on different platforms, it is not about being able to switch libraries at any time. Now that you've "standardized hibernate" I will be able to run EJB 3.0 persistence apps by switching the persistence provider when I do change my application server: is this "more portable" than what I can have now by moving my hibernate-based application on different application servers? I strongly doubt so: especially in the first months after the implementations will have come out there will surely be a number of subtle incompatibilities, not to mention the implementation-specific features that will probably be needed to manage more complex cases. I do absolutely agree that something standard like EJB3 persistence was needed, but "portability" is not a good argument for those kinds of standardizations, and the fact that the Spring team, their achievements and their lesson have been ignored in this iteration of JEE is frankly disappointing. I will probably stick with Spring, while doing JEE 5: as you say it's a framework to be used with a JEE container.

    • So what's new ?
      2006-05-28 03:23:01  Gargamelle [View]

      Well, Ive just started with all this Java server side frameworks, but I disagree about J2EE having ignored competitors lessons. In fact, dependency injection - POJO testable objects seems spring based, annotations configuration use seems xdoclet based and persistence API seems a lightweight solution Hibernate-JDO based. Still, J2EE has dependency on EJB Container if you use EJBs. But you can use the Persistence API absolutelly stand alone from EJB Container, albeit you could need remote beans, then you must use the EJB Container.
      I think J2EE team has been aware of their own mistakes and advantages and have tried to merge all the successful ideas into one strong especification. Any way I already have to investigate more!
  • So what's new ?
    2006-01-11 00:28:28  GerritCap [View]

    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,...





    Gerrit
  • So what's new ?
    2006-05-28 03:10:58  Gargamelle [View]

    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.

    Umm... have do you read we are talking about J2EE 5.0?