title: How can I get a Spring bean injected in my custom Wicket model class?
body: <p>In a custom Wicket class, not unlike the following, I'm using a service bean which should be injected by Spring, as defined with the SpringBean annotation (from the wicket-spring project).</p>
  
  <pre><code>public class ReportExportFileModel extends AbstractReadOnlyModel&lt;File&gt; {
  
      @SpringBean(name = "reportService")
      ReportService reportService;
  
      ReportDto reportDto;
  
      ReportExportFileModel(ReportDto reportDto) {
          this.reportDto = reportDto;
      }
  
      @Override
      public File getObject() {
          try {
              return reportService.generatePentahoReport(reportDto);
          } catch (ReportGenerationException e) {
             // ...
          }
      }
  }
  </code></pre>
  
  <p>However, this doesn't work: <code>reportService.generatePentahoReport()</code> fails with NullPointerException, because <strong>the bean has not been injected by Spring for some reason</strong>. </p>
  
  <p>Curiously, I've used the exact same Model code as anonymous inner class on a Wicket Page, and there was no problem there.</p>
  
  <p>How can I fix this?</p>