Create a gist now

Instantly share code, notes, and snippets.

anonymous /
Created Oct 12, 2012

What would you like to do?
Creating a WicketApplication through Guice
public class HomePage extends WebPage {
private Injector injector;
public HomePage(final PageParameters parameters) {
String hello = injector.getInstance(Key.get(String.class, Names.named("hello")));
add(new Label("hello", hello));
public class TestHomePage {
private WicketTester tester;
public void setUp() {
Injector injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(Key.get(String.class, Names.named("hello"))).toInstance("world!");
tester = new WicketTester(new WicketApplication(injector));
public void homepageRendersSuccessfully() {
tester.assertLabel("hello", "world!");
public class WicketApplication extends WebApplication {
private final Injector injector;
public WicketApplication(Injector injector) {
this.injector = injector;
public Class<HomePage> getHomePage() {
return HomePage.class;
public void init() {
getComponentInstantiationListeners().add(new GuiceComponentInjector(this, injector));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment