title: JavaConfig - Spring JPA Hibernate - @EnableTransactionManagement
body: <p>I am trying to setup a demo project with Spring4, Hibernate and a HSQLDB-Database with a JavaConfig and a Tomcat8-Server. I followed several tutorials but all ends up in the same exception.</p>
  
  <p>Here is my Configuration:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @Slf4j
  public class DatasourceConfig
  {
  
  @Bean
  DataSource dataSource()
  {
      DataSource dataSource = null;
      JndiTemplate jndi = new JndiTemplate();
      try 
      {
          dataSource = (DataSource) jndi.lookup("java:comp/env/jdbc/testdb");
      } 
      catch (NamingException e) 
      {
          log.error(e.toString());
      }
      return dataSource;
  }
  
    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() 
    {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setDataSource(dataSource());
        entityManagerFactoryBean.setPackagesToScan("packageNameWithModels");
  
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
        entityManagerFactoryBean.setJpaProperties(hibProperties());
  
        return entityManagerFactoryBean;
    }
  
     @Bean
     public PlatformTransactionManager transactionManager()
     {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
        return transactionManager;
     }
  
  
  
     @Bean
     public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
        return new PersistenceExceptionTranslationPostProcessor();
     }
  
  
    private Properties hibProperties() 
    {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
        properties.put("hibernate.show_sql", "true");
        return properties;        
    }     
  
  }
  </code></pre>
  
  <p>Maven install works like a charm but when I try to start the tomcat8-Server I get the follow error:</p>
  
  <pre><code>WARNUNG: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]: Factory method 'transactionAdvisor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionInterceptor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
  Mär 09, 2016 2:23:12 PM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean destroy
  INFORMATION: Closing JPA EntityManagerFactory for persistence unit 'default'
  Mär 09, 2016 2:23:12 PM org.apache.catalina.core.ContainerBase startInternal
  SCHWERWIEGEND: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springmvc]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:192)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springmvc]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      ... 6 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]: Factory method 'transactionAdvisor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionInterceptor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at ag.bpc.springmvc.config.WebapplicationInitializer.onStartup(WebapplicationInitializer.java:19)
      at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  </code></pre>
  
  <p>In my understanding the @EnableTransactionManagment-annotation searches for a transaction-manager bean, finds it but is not able to find the entity manager that is set by code:</p>
  
  <pre><code>transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
  </code></pre>
  
  <p>Maybe someone can help me out? 
  Thanks in advance
  Pete</p>