what is the difference between DataSourceTransactionManager and ResourcelessTransactionManager?
Asked Answered
A

1

6

What is the difference between org.springframework.jdbc.datasource.DataSourceTransactionManager and org.springframework.batch.support.transaction.ResourcelessTransactionManager

<bean id="batchTransactionManager" class=
  "org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
  
<bean id="batchJobLauncher"
  class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="batchJobRepository" />
    <property name="taskExecutor">
        <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    </property>
</bean>

In the above code is it correct to use resourcelesstransactionmanager? Or should i use datasourcetransactionmanager? What are the differneces and when to use them?

Argot answered 24/5, 2019 at 6:42 Comment(0)
I
14

Spring Batch requires a PlatformTransactionManager to apply its transaction semantics when driving a job and interacting with the job repository.

ResourcelessTransactionManager is a No-Op implementation of PlatformTransactionManager which means there will be no real transaction ongoing against a transactional resource (hence the term Resourceless). You can use it when you don't really need (or care about) transactional behaviour, for example in tests/prototypes or when using a non-transactional job repository. This class is provided by Spring Batch and is not recommended to use for production.

DataSourceTransactionManager on the other hand is from Spring Framework and is used to drive transactions against a JDBC DataSource (which could be a real database or an in-memory one). This transaction manager is typically used in Spring Batch to store batch meta-data in a relational database as a job repository.

Icelandic answered 24/5, 2019 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.