Hi,

On Mon, Jun 24, 2013 at 11:08 PM, Michael Chandler <
michael.chand...@onassignment.com> wrote:

> Joachim,
>
> This was a phenomenal write-up.  Thank you so much for this extremely
> helpful guide.  Much appreciated!
>
> Regards,
>
> Mike
>
> -----Original Message-----
> From: Joachim Schrod [mailto:jsch...@acm.org]
> Sent: Monday, June 24, 2013 12:28 PM
> To: users@wicket.apache.org
> Subject: Re: Wicket with Spring for IOC
>
> Michael Chandler wrote:
> > I'm using Wicket with Spring for dependency injection and at first
> > really struggled with what appears to be Wicket serializing my
> > application context.
>
> Then you probably don't use wicket-spring. Or you store your app context
> in a Wicket component, e.g., a page.
>
> The "official" documentation is
> https://cwiki.apache.org/confluence/display/WICKET/spring.html
> IMHO it's problematic because it tells you first about things you don't
> want to use.
>

Feel free to update the wiki


>
> There's a chapter in the new free Wicket guide, but it's very basic as
> well.
>

Or create a ticket at https://code.google.com/p/wicket-guide/issues/list to
be improved.


>
> So, here's my method / recommendation:
>
> 1. I use Maven. One needs a dependency to org.apache.wicket:wicket-spring.
>
> 2. My application object is a Spring Bean. It's declared in
>    WEB-INF/applicationContext.xml. web.xml tells about it
>
>   <listener>
>     <description>
>       Load WebApplicationContext of Spring from
> WEB-INF/applicationContext.xml.
>     </description>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>   </listener>
>   <filter>
>     <filter-name>Wicket Application Filter</filter-name>
>
> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>     <init-param>
>       <param-name>applicationFactoryClassName</param-name>
>
> <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
>     </init-param>
>     <init-param>
>       <param-name>ignorePaths</param-name>
>       <param-value>/js,/css,/images</param-value>
>     </init-param>
>   </filter>
>
>   (Adapt your ignorePaths as needed.)
>
> 3. Within your application object, you need to call
>
>         this.getComponentInstantiationListeners().add(new
> SpringComponentInjector(this));
>
>    Usually, it's sufficient to call that in init().
>    Except if you're using converters that need access to Spring beans,
>    e.g., services. Then, newConverterLocator() is a better place for it.
>
> 4. Within your Wicket components, tag Spring beans with an annotation:
>
>         @SpringBean BeanClass beanObject;
>
>    Wicket will inject the Spring bean. Of course, you need to *declare*
>    your Spring bean in Spring! I.e., you either need to declare an
>    application-level bean in WEB-INF/applicationContext.xml or you need
>    to trigger annotation scanning by Spring. (<context:component-scan>
>    and friends.)
>
> 5. If you need Spring beans in a behavior, resource, or any other
> non-component
>    class, you need to tell Wicket about it. For that, you call
>
>         Injector.get().inject(this);
>
>    in that class' constructor. Afterwards, @SpringBean injections
>    work in that class.
>
> That's all. It just works.
>
> HTH,
>         Joachim
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Joachim Schrod, Roedermark, Germany
> Email: jsch...@acm.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to