Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed alternative workaround (it doesn't work)

...

Tip

When using Guice to inject objects that you reference directly (without an interface), and you´re using constructor injection on these Objects, add a protected non-arg constructor to make it work.

Alternatively, avail yourself of the Guice provider mechanism. This solution is preferred as it allows values to be both lazy loaded, and lazy re-loaded for page deserialization and reinjection.

This is why:

Wicket-Guice, or - to be more precise -, Wicket-IOC uses a dynamically created Proxy to intercept the calls to the Guice-Injected reference. When dealing with an interface, the proxy is created with the JDK-provided proxy facility.
If - on the other hand - it is not, Wicket-IOC uses CGLib to create a subclass instead and adds an Interceptor, so that any calls to the newly created instance of this subclass can be rerouted to the original reference.
Within here is a litte problem: Wicket-IOC has to create an Instance of the newly created subclass.

...