thymeleaf / thymeleafexamples-layouts

Layouts - Companion application for the "Thymeleaf Layouts" article at the Thymeleaf website: http://www.thymeleaf.org/documentation.html http://www.thymeleaf.org
Apache License 2.0
245 stars 174 forks source link

PlatformTransactionManager In JpaConfig.java #2

Open phxism opened 8 years ago

phxism commented 8 years ago

the PlatformTransactionManager just new A JpaTransactionManager and return it as a bean , @Bean public PlatformTransactionManager annotationDrivenTransactionManager() { return new JpaTransactionManager(); } but according to the javadoc "org.springframework.transaction.PlatformTransactionManager implementation for a single JPA javax.persistence.EntityManagerFactory. Binds a JPA EntityManager from the specified factory to the thread, potentially allowing for one thread-bound EntityManager per factory. " so i change to this @Override @Bean(name="transactionManager") public PlatformTransactionManager annotationDrivenTransactionManager() { JpaTransactionManager transactionManager= new JpaTransactionManager(); transactionManager.setEntityManagerFactory(configureEntityManagerFactory().getObject()); return transactionManager; } I pass in an emtityManagerFactory to the JpaTransactionManager but I got an error when the application init.here is the stacktrace java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Mon Jun 06 10:45:19 SGT 2016]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359) [spring-context-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:888) [spring-context-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) [spring-context-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:551) [spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) [spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5014) [catalina.jar:7.0.52] at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5659) [catalina.jar:7.0.52] at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) [catalina.jar:7.0.52] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) [catalina.jar:7.0.52] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.52] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.52] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_77] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77] so ,why don't you 'setEntityManagerFactory()' just create a JpaTransactionManager ,for avoid error?or somewhere else i don't know?

kolorobot commented 7 years ago

There will be a completely new version of the sample soon. Stay tuned.