我正在使用 appengine 和 Objectify 来访问我的数据源。我的业务层使用 Spring。为了玩数据,我使用 objectify-appengine-spring factory .
我想使用基于注释的本地事务。您知道我可以直接将其作为 spring bean 插入的现有实现吗?
我真的很想避免使用线程局部变量实现我自己的事务提供程序的痛苦。
最佳答案
检查 LushLife 的 ObjectifyTransactionManager
here或 here .
需要 Spring XML 配置(您可以找到 here 或 here ):
<!-- ObjectifyManager -->
<bean id="objectifyManager" class="ex.objectify.spring.ObjectifyManager">
<property name="basePackage" value="gso.model" />
</bean>
<!-- ObjectifyFactoryBean -->
<bean id="objectifyFactory" class="ex.objectify.spring.ObjectifyFactoryBean">
<property name="manager" ref="objectifyManager" />
</bean>
<!-- Custom TransactionManager implementation -->
<bean id="transactionManager" class="ex.objectify.spring.ObjectifyTransactionManager">
<property name="manager" ref="objectifyManager" />
</bean>
<!-- Necesary to enable use of @Transactional in your services -->
<tx:annotation-driven />
不要忘记用 @Transactional 注释您的事务方法或类.
特别感谢作者project .
关于使用 Objectify 和 Appengine 进行 Spring 事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8940460/