public abstract class AbstractSpringDependencies extends Object implements org.apache.wicket.util.io.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;
// ...
}
}
Modifier | Constructor and Description |
---|---|
protected |
AbstractSpringDependencies()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
AbstractSpringDependencies |
clone() |
protected void |
init()
Injects dependencies.
|
protected Object |
readResolve()
Called during deserialization by the JVM.
|
protected AbstractSpringDependencies()
init()
.protected void init()
protected Object readResolve()
init()
.public AbstractSpringDependencies clone()
Copyright © 2015. All rights reserved.