title: How to load/access a bean (@Resource) in a custom Velocity tool
body: <p>I realize this is a slightly funky thing to need to do, but I'm trying to access my Spring messageSource bean from a custom Velocity tool.</p>
  
  <p>In most of our codebase, I'm able to just set up a member variable and load it like this:</p>
  
  <pre><code>@Resource(name = "messageSource")
  private AbstractMessageSource _msgSource;
  </code></pre>
  
  <p>However, in this circumstance, this doesn't load the bean, I'm assuming because the Velocity tools get instantiated in a way that doesn't allow normal bean loading to occur. Or it doesn't want to initialize the bean for an application scoped Velocity tool.</p>
  
  <p>The tool is set up in the toolbox.xml as follows:</p>
  
  <pre><code>&lt;tool&gt;
      &lt;key&gt;calendarTool&lt;/key&gt;
      &lt;scope&gt;application&lt;/scope&gt;
      &lt;class&gt;...&lt;/class&gt;
  &lt;/tool&gt;
  </code></pre>
  
  <p>I haven't been able to find anything online that explains either how to do this or why it doesn't work.</p>