title: Spring Controller Injected Properties Turn Null
body: <p>I have a situation very similar to "<a href="https://stackoverflow.com/questions/7280115/inject-a-file-resource-into-spring-bean">Inject a file resource into Spring bean</a>"</p>
  
  <p>I have a controller that uses some .jasper compiled files and I am declaring them as such</p>
  
  <pre><code>//...
  @Controller
  public class InvoicingController {
  
  private Resource quoteTemplate;
  ...//
  </code></pre>
  
  <p>And in my context configuration file</p>
  
  <pre><code>&lt;bean id="invoicingController" class="x.x.InvoicingController"&gt;
      &lt;property name="quoteTemplate" value="/WEB-INF/jasper/Quote.jasper" /&gt;
  ...
  </code></pre>
  
  <p>I set a breakpoint on the <code>setQuoteTemplate()</code> function and it is being called and the <code>Resource</code> object is being set properly when I initialize the container.   However when I actually hit the controller <code>quoteTemplate</code> is null.</p>
  
  <p>I am under the understanding that Controllers are singletons and unless there is a gap in my understanding I am not sure why the values that are set during the container's initialization become null when I hit a url that the controller handles.</p>
  
  <p>EDIT:</p>
  
  <p>Thanks @Sotirios Delimanolis</p>
  
  <p>I ended up declaring beans as such:</p>
  
  <pre><code>    &lt;bean id="quoteFile" class="java.io.File"&gt;
          &lt;constructor-arg value="resources/jasper/Quote.jasper" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="quoteTemplate" class="org.springframework.core.io.FileSystemResource"&gt;
          &lt;constructor-arg ref="quoteFile" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>And then <code>@Autowire</code>ing the dependencies as such</p>
  
  <pre><code>@Autowired @Qualifier("quoteTemplate") private Resource quoteTemplate;
  </code></pre>
  
  <p><code>@Qualifier</code> is used because I have multiple <code>Resource</code> implementation classes declared as beans and this makes sure the correct one gets used.</p>