Skip to content

PlatformTransactionManager In JpaConfig.java #2

Description

@phxism

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions