title: Property 'entityManagerFactory' is required
body: <p>I just started to develop an application that's meant to support an already existing web project, therefore the business and persistence layers already exist and are working very well within that web application. Now as I use the libs for both layers in my console application I get an error that the JpaTransactionManager requires the entityManagerFactory, which is weird, because it doesn't throw an exception in my web app. All I do in my console application is creating the application context</p>
  
  <pre><code>public static void main(String[] args) {
      ApplicationContext ctx = new ClassPathXmlApplicationContext("engine-context.xml");
  
  }
  </code></pre>
  
  <p>the engine-context.xml:</p>
  
  <pre><code>&lt;import resource="business-context.xml" /&gt;
  &lt;import resource="persistence-context.xml" /&gt;
  
  &lt;tx:annotation-driven transaction-manager="myTxManager" proxy-target-class="true"/&gt;
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spielerService' defined in class path resource [business-context.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'myTxManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTxManager' defined in class path resource [persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'entityManagerFactory' is required
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
  at org.boogerrangers.engine.EngineMain.main(EngineMain.java:14) 
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'myTxManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTxManager' defined in class path resource [persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'entityManagerFactory' is required
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:86)
      at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:100)
      at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:107)
      at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:278)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:848)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:820)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:446)
      ... 10 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'myTxManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTxManager' defined in class path resource [persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'entityManagerFactory' is required
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
      ... 26 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTxManager' defined in class path resource [persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'entityManagerFactory' is required
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
      ... 32 more
  Caused by: java.lang.IllegalArgumentException: Property 'entityManagerFactory' is required
      at org.springframework.orm.jpa.JpaTransactionManager.afterPropertiesSet(JpaTransactionManager.java:257)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
      ... 39 more
  </code></pre>
  
  <p>All I do in my web application is to define the context XML files in the web.xml</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          /WEB-INF/applicationContext.xml
          classpath:persistence-context.xml   
          classpath:business-context.xml          
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>there's no more magic in the applicationContext.xml </p>
  
  <pre><code>&lt;!-- SESSION: --&gt;
      &lt;bean name="spielerSession" class="org.boogerrangers.persistence.dom.SpielerLogin" scope="session"  &gt;
          &lt;aop:scoped-proxy/&gt;
      &lt;/bean&gt;
  
  &lt;!-- FILTER: --&gt;
      &lt;bean name="authFilter" class="org.boogerrangers.game.filter.AuthFilter" &gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>--</p>
  
  <p>persistence-context</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  
      &lt;bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="xxx" /&gt;
          &lt;property name="username" value="xxx" /&gt;
          &lt;property name="password" value="xxx" /&gt;
      &lt;/bean&gt;
  
  
      &lt;tx:advice id="txAdvice" transaction-manager="myTxManager"&gt;
          &lt;tx:attributes&gt;
              &lt;tx:method name="get*" read-only="true" /&gt;
              &lt;tx:method name="find*" read-only="true" /&gt;
              &lt;tx:method name="*" rollback-for="Exception" /&gt;
          &lt;/tx:attributes&gt;
      &lt;/tx:advice&gt;
      &lt;aop:config&gt;
          &lt;aop:pointcut id="servicePointcut" expression="execution(* *..*Service*.*(..))" /&gt;
          &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" /&gt;
      &lt;/aop:config&gt;
  
      &lt;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="persistenceUnitName" value="xxx"&gt;&lt;/property&gt;
          &lt;property name="loadTimeWeaver"&gt;
              &lt;bean
                  class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  ... DAOs ...
  </code></pre>
  
  <p>more information needed?</p>
  
  <p>as a dirty workaround I created a new persistence-context and use this instead but that's confusing and I don't wanna have redundant configurations. I also created a second webapp doing the same thing as in the standalone app with no thrown exceptions.</p>
  
  <p>thanks in advance.</p>