English 中文(简体)
如何将春天交易传播到另一个深层?
原标题:How to propagate Spring transaction to another thread?

也许,我做了一些错误的事情,但我无法为以下局势找到一个很好的办法。

我愿用Spring Batch underneath执行职务。 工作通过预设的<条码>AsyncTaskExecutor在单独的校对进行。 在我的单位试验中,我要:

  1. Create few domain objects and persist them via DAO
  2. Invoke the service method to launch the job
  3. Wait until the job is completed
  4. Use DAO to retrieve domain objects and check their state

显然,以上所有事项都应在一次交易中执行,但不幸的是,

我想到的想法:

  • Commit the transaction#1 after step (1). Is not good, as the DB state should be rolled back after the unit test.
  • Use Isolation.READ_UNCOMMITTED in job configuration. But this requires two different configurations for test and for production.
最佳回答

我认为,最简单的解决办法是,在试验执行期间,将“Launcher”与“SyncTaskExecutor”混为一谈,这样,工作就与测试和分享交易一样。

任务执行者组合可移至单独的春季配置Xml文档。 有两个版本:一个是试验期间使用的SyncTaskExecutor,另一个是供生产使用的AsyncTaskExecutor。

问题回答

如果你确实想要不同的组合,我就建议把孤立政策排在你的组合中,将其价值从财产档案中去掉,以便你不要用一套不同的春季会议来进行测试和推测。

But I agree that using the same policy production uses is best. How vast is your fixture data, and how bad would it be to have a setUp() step that blew away and rebuilt your data (maybe from a snapshot, if it s a lot of data) so that you don t have to rely on rollbacks?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签