org.wicketstuff.springreference
Class AbstractSpringDependencies

java.lang.Object
  extended by org.wicketstuff.springreference.AbstractSpringDependencies
All Implemented Interfaces:
Serializable, Cloneable, IClusterable

public abstract class AbstractSpringDependencies
extends Object
implements IClusterable, Cloneable

This class together with SpringReferenceSupporter makes it possible to use spring annotation driven injection with wicket (for example @Autowired and @Qualifier annotated fields). It has most of the benefits of SpringReference (except lazy lookup) so this can be used too where @SpringBean from wicket-spring fails (no dynamic proxies used, serialization supported).

Instances of this class use the SpringReferenceSupporter for bean lookup, so it must be registered in your wicket WebApplication init() method ( SpringReferenceSupporter.register(this);). Otherwise you will get NullPointerException during instantiation. See SpringReferenceSupporter for more information.

Probably this is the most ugly looking in code from the spring-wicket integration alternatives, however this is the closest to the vanilla spring injection.
The base idea is that the spring dependencies are encapsulated into a subclass of this class. Dependencies are (re)injected during instantiation, deserialization and cloning.

Usage:

 
 public class MySession extends AuthenticatedWebSession
 {
        private static final long serialVersionUID = 1L;
        
        // This nested class holds all our spring dependencies. Annotated in spring style.
        static class Deps extends AbstractSpringDependencies
        {
                private static final long serialVersionUID = 1L;
        
                @Autowired
                @Qualifier("authenticationManager")
                transient AuthenticationManager authenticationManager;
 
                @Autowired
                transient AbstractRememberMeServices abstractRememberMeServices;
        }
        
        private final Deps deps = new Deps();
        
        // ...
 
        public boolean authenticate(String username, String password)
        {
                // ...
                deps.authenticationManager.authenticate(token);
                AbstractRememberMeServices rememberMeServices = deps.abstractRememberMeServices;
                // ...
        }
 }
 
 

Author:
akiraly
See Also:
Serialized Form

Constructor Summary
protected AbstractSpringDependencies()
          Constructor.
 
Method Summary
 AbstractSpringDependencies clone()
           
protected  void init()
          Injects dependencies.
protected  Object readResolve()
          Called during deserialization by the JVM.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSpringDependencies

protected AbstractSpringDependencies()
Constructor. Calls init().

Method Detail

init

protected void init()
Injects dependencies.


readResolve

protected Object readResolve()
Called during deserialization by the JVM. Calls init().

Returns:
this

clone

public AbstractSpringDependencies clone()
Overrides:
clone in class Object


Copyright © 2012. All Rights Reserved.