春季4建议替换JpaTemplate [英] Spring 4 recommended replacement of JpaTemplate

查看:103
本文介绍了春季4建议替换JpaTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧项目,该项目使用的是Spring 3.0.x,并使用了Spring提供的 JpaTemplate 实现。

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

但是,在升级到Spring 4.0.x之后,我了解到 JpaTemplate 自Spring 3.2起已被弃用

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

我看到了一些建议,可以将 JpaTemplate EntityManager 一起简单重构。

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

但是,用 EntityManager 替换 JpaTemplate 是不够的,因为我发现此项目正在包装 JpaTemplate 调用 JpaCallback ,而后者又使用了entitymanager。我想使用回调的原因是允许这些DAO调用异步运行。

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.

是否有关于如何重构使用JpaTemplate和升级到Spring 4时是JpaCallback类吗?

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

推荐答案

除了替换 JPATemplate ,则应使用< context:annotation-config /> 启用注释配置,或配置 PersistenceAnnotationBeanPostProcessor 来启用注释配置将 EntityManager 注入到DAO中。
如果您已激活< context:component-scan /> ,则可以使用迁移前的所有功能。

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.

这篇关于春季4建议替换JpaTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆