wood burning stoves 2.0*
The moose likes Features new in Java 7 and the fly likes Dependency Injection in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Dependency Injection in Java" Watch "Dependency Injection in Java" New topic
Author

Dependency Injection in Java

Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

I checked the Table of Contents for "The Well Grounded Java Developer".

Chapter 3 is on Dependency Injection.

Some basic questions:

1. Is the DI in Java similar to what Spring framework offers? Is it a remake?
2. Does Java just provide the Spec for DI and we need some vendor implementation for this spec to utilize DI?
3. How can I make my current Java code to utilize Java DI?
4. Do I necessarily need to use Guice API's to achieve Java DI?
5. Do we have any other implementation available for Java DI other than Guice?


SCEA EE5, CSM, PMP, IBM OOAD with UML, SCDJWS, SCWCD, SCJP 1.5
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

1) It is a standard inspired by Spring (and more)
2) I believe you need some sort of DI container.
3) Look for things you'd like to decouple. For example, when writing test code, it is common to inject an implementation of an interface.
4) No
5) Spring and PicoContainer.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

Spring framework on DI was there before Java came up with any DI specs.
How can it be that Spring is implementing java DI?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

This is a very common pattern is software. Good ideas become design patterns, design patterns are bult into frameworks (like Spring) and then into a language itself (the JSR-330 std for Java). Spring 3.x simply implements the common JSR-330 std + some extras.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Shiv,
That's how JPA came about too.

1) Hibernate started.
2) JPA spec came out
3) Hibernate provided set of APIs to be compliant with JPA spec
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency Injection in Java
 
Similar Threads
* Welcome Dhanji Prasanna
Spring, in Spring-Struts-Hibernate application
Wicket in Action - Wicket's friends
Dependency injection limitation in JEE ?
Spring in Action - Alternatives