I know this question is over 9 month old, but I stumbled over the same problem
and managed to fix it. The solution from Andrei Stefan is one step in the
right direction. Surprisingly, when you call getObject() within the method to
retrieve the entityManagerFactory, it will throw a NPE, but if you call the
exact same method outside of the entityManagerFactory method it will work.
@Bean public PlatformTransactionManager transactionManager() { return new JpaTransactionManager(entityManagerFactory().getObject()); } @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setGenerateDdl(true); jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect"); factory.setJpaVendorAdapter(jpaVendorAdapter); return factory; } @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build(); }


