title: How to call custom data loader on Spring application start
body: <p>I'm trying to load some data to my DB on application start. I have a bean defined for this purpose</p>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;bean class="com.project.loader.DataLoader" 
  id="DataLoader" 
  depends-on="entityManagerFactory" 
  scope="singleton"/&gt;
  </code></pre>
  
  <p>class:</p>
  
  <pre><code>@RooJavaBean
  @RooConfigurable
  public class DataLoader implements InitializingBean
  </code></pre>
  
  <p>It is being executed however on first persist() method being call, Spring throws me following error:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
  at com.project.lib.model.extensions.i18n.Locale_Roo_Jpa_ActiveRecord.entityManager_aroundBody0(Locale_Roo_Jpa_ActiveRecord.aj:19)
  at com.project.lib.model.extensions.i18n.Locale_Roo_Jpa_ActiveRecord.ajc$interMethod$com_project_lib_model_extensions_i18n_Locale_Roo_Jpa_ActiveRecord$com_project_lib_model_extensions_i18n_Locale$entityManager(Locale_Roo_Jpa_ActiveRecord.aj:1)
  at com.project.lib.model.extensions.i18n.Locale.entityManager(Locale.java:1)
  </code></pre>
  
  <p>Previousely it was working when I defined DataLoader in following way:</p>
  
  <pre><code>@Component
  @Configurable
  public class DataLoader implements ApplicationListener
  </code></pre>
  
  <p>but using raw types is not good practice so I would like to switch</p>
  
  <p>How can I make it work?</p>
  
  <p>Spring version: 3.1</p>