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


1 to 2 of 2
1 to 2 of 2