No transactional EntityManager available

人走茶凉 提交于 2019-12-01 06:14:31
Sam Brannen

By declaring

@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })

you have completely (albeit unintentionally) disabled support for test-managed transactions. The reason is that you have omitted TransactionalTestExecutionListener from the list of declared listeners.

Note, however, that TransactionalTestExecutionListener is declared transparently by default. Thus, when you delete your @TestExecutionListeners declaration from your test class, TransactionalTestExecutionListener is once again enabled.

You can of course find details in the Spring Reference Manual here.

Regards,

Sam (author of the Spring TestContext Framework ;) )

I think EntityManager is null.Try Like this,may be it work

private EntityManager entityManager = null;

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!