Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone compare Google Guice and Spring DI?

Can anyone list the pros and cons of Google guice over Spring DI? Both satisfies the dependency injection in one way or the other. In which cases we can go for google guice and in which cases we can go for Spring DI.

like image 556
raddykrish Avatar asked May 09 '12 01:05

raddykrish


1 Answers

Well, I've used both for different things. I think a lot of it depends on preference.

I'm not going to come up with an exhaustive comparison here, because others have done so on the web. In my experience, Spring fits in better with the Java EE side of things (web apps and the like), and Guice fits in better in with other types of applications (such as in Eclipse). I will say that the arguments against Spring that discuss its "unwieldy" XML configuration are no longer true. As of Spring 3, application contexts can be (almost) completely configured using annotated Java classes if you so desire.

Also keep in mind that Guice is much newer than Spring and, to a certain extent, the development team was able to base their code from what Spring learned developing a DI framework. In Guice, there seems to be a lot more flexibility for more corner use cases (such as the @Assisted annotation for partial factory-based injection).

like image 184
Jonathan W Avatar answered Oct 20 '22 22:10

Jonathan W