Module org.apache.wicket.spring
Class SpringComponentInjector
java.lang.Object
org.apache.wicket.injection.Injector
org.apache.wicket.spring.injection.annot.SpringComponentInjector
- All Implemented Interfaces:
IComponentInstantiationListener
,IBehaviorInstantiationListener
public class SpringComponentInjector
extends Injector
implements IComponentInstantiationListener, IBehaviorInstantiationListener
IComponentInstantiationListener
that injects component and behavior properties
annotated with SpringBean
annotations.
To install in yourapplication.init() call
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
Only Wicket Component
s and Behavior
s are automatically injected, other classes
such as Session
, Model
, and any other POJO can be injected by calling
Injector.get().inject(this)
in their constructor.
- Author:
- Igor Vaynberg (ivaynberg), Justin Lee
-
Constructor Summary
ConstructorDescriptionConstructor used when spring application context is declared in the spring standard way and can be located throughWebApplicationContextUtils.getRequiredWebApplicationContext(jakarta.servlet.ServletContext)
.SpringComponentInjector
(WebApplication webapp, org.springframework.context.ApplicationContext ctx) ConstructorSpringComponentInjector
(WebApplication webapp, org.springframework.context.ApplicationContext ctx, boolean wrapInProxies) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Injects the specified object.void
onInstantiation
(Behavior behavior) Called when a behavior instance is createdvoid
onInstantiation
(Component component) Called for every component that is instantiated.static void
setDefaultContext
(WebApplication webapp, org.springframework.context.ApplicationContext context) Set the default context for the given webapp.
-
Constructor Details
-
SpringComponentInjector
Constructor used when spring application context is declared in the spring standard way and can be located throughWebApplicationContextUtils.getRequiredWebApplicationContext(jakarta.servlet.ServletContext)
.- Parameters:
webapp
- wicket web application
-
SpringComponentInjector
public SpringComponentInjector(WebApplication webapp, org.springframework.context.ApplicationContext ctx) Constructor- Parameters:
webapp
- wicket web applicationctx
- spring's application context
-
SpringComponentInjector
public SpringComponentInjector(WebApplication webapp, org.springframework.context.ApplicationContext ctx, boolean wrapInProxies) Constructor- Parameters:
webapp
- wicket web applicationctx
- spring's application contextwrapInProxies
- whether or not wicket should wrap dependencies with specialized proxies that can be safely serialized. in most cases this should be set to true.
-
-
Method Details
-
inject
Description copied from class:Injector
Injects the specified object. This method is usually implemented by delegating toInjector.inject(Object, IFieldValueFactory)
with someIFieldValueFactory
-
onInstantiation
Description copied from interface:IComponentInstantiationListener
Called for every component that is instantiated. This method is called during construction, so do not depend on the construction being completed yet. The id is guaranteed to be set before this call.- Specified by:
onInstantiation
in interfaceIComponentInstantiationListener
- Parameters:
component
- the component that is being instantiated.
-
onInstantiation
Description copied from interface:IBehaviorInstantiationListener
Called when a behavior instance is created- Specified by:
onInstantiation
in interfaceIBehaviorInstantiationListener
-
setDefaultContext
public static void setDefaultContext(WebApplication webapp, org.springframework.context.ApplicationContext context) Set the default context for the given webapp.- Parameters:
webapp
- web applicationcontext
- context to use as default if non is explicitely specified for the injector
-