Wicket, Guice, Warp and Hibernate: A Quickstart Project
I’m a big fan of the Wicket framework. Its stateful component-based model, markup inheritance, complete lack of XML and JSP and excellent AJAX support make web development such a great experience.
In a typical Wicket application you use Spring for dependency injection and transaction management, and Hibernate/JPA for data persistence. This makes a powerful stack that powers many successful web applications.
However, when you get used to Wicket you start missing its convention-over-configuration and zero-XML style while working in other layers of the app.
Update: You could use Spring’s JavaConfig and write your application configuration using Java annotations instead of XML, which provides type safety and a pure Java setup. Still, some developers (me included) feel uncomfortable using Spring just for dependency injection.
Looking for alternatives to Spring, I’ve found that the agile lightweight Guice framework and Wicket play nice together. You can drop Spring and adopt Guice instead, but that leaves your project without transaction management. The missing piece of the puzzle is warp-persist, a transactional framework for Guice created by Dhanji Prasanna. Now you’ve got a complete pure-Java replacement for Spring. The only remaining XML here are the Hibernate mapping files, which are gone if you start using Hibernate Annotations.
Quoting Peter Mularien: “One of the reasons that I think Spring has become so popular in web applications is that there simply hasn’t been another widespread web application stack that (1) is free, (2) is not Java EE, and (3) doesn’t involve JSF”. Well, that’s not true anymore.
Lightweight frameworks like Guice are viable alternatives to Spring. I think the strongest point of a pure-Java solution is that everything is subject to automatic refactorings. You no longer have to mantain your Java code and references to it from XML files in sync. If you are applying agile methodologies, this is a serious reason for considering this stack instead of the more conservative Spring/Hibernate combo.
To get started, read the links below:
- http://www.mularien.com/blog/2007/11/28/bleeding-edge-transactional-wicket-web-applications-with-warp-and-guice/
- http://richard-wilkinson.co.uk/2008/08/17/more-warped-wicket/
And finally:
Download the quickstart project
Comments and patches welcome.

November 9th, 2008 at 3:04 pm
hi
Thanks for this quickstart project, it’s a real helper for beginners like me.
I have a remark however : why didn’t you override the getSession() method in your WicketGuiceWarpHibernateApplication ? Wouldn’t it be nicer this way to interact with Wicket ?
Thanks again !
Nono
November 10th, 2008 at 11:14 am
you can config spring with java, much like wicket (http://www.springsource.org/node/815). i don’t think spring and guice should really be considered competitors, spring does much more than guice, though guice has come nicer concepts.
i’ve used javaconfig for a while, even tho it isn’t a full release yet, and i haven’t had any problems. i like having type-safe configuration. in fact, i’d never really thought about xml being type-unsafe until watching a bob lee presentation about guice
November 11th, 2008 at 2:33 am
Hi Nono,
I’m glad you liked it. I’m using a ServletScopes.SESSION scoped object (MySession) instead of overriding getSession() in order to show how to use different binding scopes.
Binding an object in session scope means that you will be available to inject it in any part of the application, not just the presentation layer. You can still override getSession() for storing presentation layer-specific data if you want, but using a session scoped object generally leads to cleaner code and makes writing tests easier.
November 11th, 2008 at 3:05 am
Hi Graham,
I think Spring’s JavaConfig project is a big step forward, and many applications will benefit from it.
Even if JavaConfig gives type safety to your configuration code in the same way Guice does, I don’t consider them competitors. Spring is much more than dependency injection and AOP: it’s a full enterprise stack.
Guice is a nice alternative to Spring if you only need the features it provides. That said, lots of developers will still use Spring if they just need a dependency injection container simply because they are already used to it. In the end, it’s a matter of taste. I personally like Guice’s API and low code footprint, so I stick to it whenever I can.
October 5th, 2009 at 2:31 pm
The quickstart app is not able to be downloaded. Is there another location for the quickstart app?
October 5th, 2009 at 11:30 pm
Hi Jeff,
Please use the following link:
http://downloads.cafesolo.com.ar/wicket/WicketGuiceWarpHibernateQuickstart.zip
Let me know if you still can’t download the project.
Thanks for your comment!
October 10th, 2009 at 6:40 pm
could you please make it with wicket 1.4.1 and guice 2.0?
thanks.
December 14th, 2009 at 12:54 pm
Do not use GuiceComponentInjector, rather use InjectionFlagCachingGuiceComponentInjector and get up to 10x better performance.
February 24th, 2010 at 8:35 am
meo: I’ll put an updated quickstart soon. Thanks for the interest.
VK: Thanks for the suggestion. I’ll take a look at it.