The 5 Minute Guice Primer
Published Mon, 22 Jun 2009 • 1 comments
I've just finished getting up to speed with Google's Guice 2.0 and have integrated it into two of my projects. It's been a very comfortable experience and I could see myself Guicifying most of my Java projects from now on.
So how is Guice different to Spring?
- No XML!
- Narrower scope: Guice only does DI and AOP, unlike Spring which covers a wide gamut of requirements.
- Heavy and mandatory use of annotations.
- ...and in my opinion, a more refined and elegant design.
I think one of the main reasons I like Guice so much is the absence of XML. I really hate XML and Guice's "Module" concept is a great replacement for text configuration. I would be interested to know how often in practice that Spring's XML configuration is changed in situations where a rebuild of the application is impossible. The argument for that sort of configuration has always seemed like a straw man to me. As a bonus of the Guice Module approach, you get type checking and compilation of your configuration. [It would be interesting to see if someone does implement an XML configurator for Guice though - I'd say it's only a matter of time].
How to get up to speed real fast?
- If you're not familiar with DI and/or AOP then do some reading. A framework can only solve a problem that you know you have.
- Watch the recent " target="_blank">Google IO tech session for the 60 minute fast-track introduction.
- The Guice wiki is helpful, but I found the external links and discussion group to be more helpful.
- Write something! It's a dead easy framework to get your head around, and the fastest way to solidify your knowledge is to do.
About the Author
Richard Nichols is an Australian software engineer with a passion for making things.
You might also enjoy reading -
- 5 Minute Guide to Clustering - Java Web Apps in Tomcat
- 1 Minute Guide - Installing Redmine on Windows
- From Wordpress to Netty - Can you spot the difference?
- Clustering Guice Java Web Applications
- Guice / Java IoC best practices - using annotations for configuration