title: Wicket integration with Spring
body: <p>I am making an application in which I want to integrate Wicket + Spring. Application is a grocery store on which user comes and buy something. I know there are two ways to do this.</p>
  
  <ol>
  <li><p>Using the annotation aprroach. Wicket-Spring integration shows various ways on how to inject Spring Beans into Wicket pages.</p>
  
  <pre><code>public class FormPage extends WebPage
  {
    @SpringBean
    private IContact icontact;
    ...
    Form&lt;Object&gt; form = new Form&lt;Object&gt;("contactForm",
       new CompoundPropertyModel&lt;Object&gt;(contact))
    {
      private static final long serialVersionUID = 1L;
  
      protected void onSubmit(Contact contact)
      {               
        icontact.saveContact(contact);
      }
    }; 
  </code></pre></li>
  <li><p>The @SpringBean is of course valid and considered a best practice by many. But there is also another approach, where your Wicket Application has the services you need.</p>
  
  <pre><code>public class YourWicketApp extends WebApplication{
    public static YourWicketApp get(){
      return (YourWicketApp) Application.get();
    }
    private ServiceA serviceA;
    // getter and setter for serviceA here
  }
  </code></pre>
  
  <p>Now in your component, call</p>
  
  <blockquote>
    <p>YourWicketApp.get().getServiceA();</p>
  </blockquote></li>
  </ol>
  
  <p><strong>I want to know</strong> which is the best way to integrate spring with wicket and what are the drawbacks in each case.</p>
  
  <p><em>However as far as I remember Wicket pages and components aren't managed by Spring container so you cannot use @Transactional annotation on them (which is a bad idea anyway - transactions belong to deeper levels).</em> <strong>Is this statement valid?</strong></p>