| Article: |
Using Dependency Injection in Java EE 5.0 | |
| Subject: | So what's new ? | |
| Date: | 2006-01-05 00:01:12 | |
| From: | GerritCap | |
|
Well this article is my first encounter with the new EJB specs and it is rather early in the morning so I might miss some important issues here but basically I don't see any difference between
|
||
Showing messages 1 through 3 of 3.
-
So what's new ?
2006-05-05 00:22:13 pbpanther [View]
-
So what's new ?
2006-03-28 23:23:44 NidhiTuli [View]
The article didn't explain in details with example How to use dependency injection using XML in EJB3. Would it be possible to get more info or some links for the same. In our application we want to use dependency injection but at compile time we don't know which class it would be, so we can't use annotation. Doing dependency injection usin XML fits to our needs. Please suggest some example for the same.
Thanks
Nidhi
-
So what's new ?
2006-01-05 13:12:24 DebaPanda [View]
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



To test with an InitialContext you have to first set up a test context somehow then insert your mock/stub object into the the context.
With dependency injection there is no dependency on an InitialContext in your code, so all you have to do is inject your mock/stub implementation of HelloWorld and you are testing.
The reason for POJOs generally is so that you can unit test your code thoroughly and even program using TDD.