Spring 4 recommended replacement of JpaTemplate

南笙酒味 提交于 2019-12-10 18:35:39

问题


I have a legacy project which was using Spring 3.0.x and made use of the JpaTemplate implementation provided by Spring.

However, after upgrading to Spring 4.0.x I learned that JpaTemplate was deprecated as of Spring 3.2

I have seen suggestions to simply refactor out the use of JpaTemplate with EntityManager.

However, replacing JpaTemplate with EntityManager is not sufficient as I discovered this project was wrapping the JpaTemplate calls in a JpaCallback, which in turn used entitymanager. I imagine the reason callbacks were used was to allow these DAO calls to be ran asynchronously.

Are there any suggested recommendations on how to refactor applications which make use of JpaTemplate and the JpaCallback class when upgrading to Spring 4?


回答1:


Additionally to replacing JPATemplate, you should enable annotation configuration using <context:annotation-config /> or configure a PersistenceAnnotationBeanPostProcessor to enable the injection of the EntityManager into the DAOs. If you have <context:component-scan /> activated, you should be fine to use all the features as it was before migration.



来源:https://stackoverflow.com/questions/35121155/spring-4-recommended-replacement-of-jpatemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!