...
Code Block | ||||
---|---|---|---|---|
| ||||
...
<servlet>
<servlet-name>wicket</servlet-name>
<servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
</init-param>
<init-param>
<param-name>applicationBean</param-name>
<param-value>wicketApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<!-- The SpringWebApplicationFactory will need access to a Spring Application context, configured like this... -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
...
|
...
Warning |
---|
Please note that you cannot use constructor argument based injection with Wicket, only accessorsetter-based injection! |
It's possible to have your annotated dependencies automatically injected on construction. For this you have to install a SpringComponentInjector in your application.
...
Code Block |
---|
class MyApplication extends WebApplication { public void init() { super.init(); getComponentInstantiationListeners().add(new SpringComponentInjector(this)); } } |
Here the page (or indeed anything derived from a Wicket {{ Wiki Markup Component
}}) will have its dependencies injected when created. _\[Constructor/superclass chaining down to the Component(final String id, final IModel model) constructor, where there's a call to getApplication().notifyComponentInstantiationListeners(this);\]_
When doing this it is important to remember not to initialize dependencies, to null or any other value, e.g.private ContactDao dao=null;
. Don't do this because the injector will run before the subclass initializes its fields, and so the dao=null
will override the created proxy with null.
...