Declarative or Programmatic Transaction in Spring

后端 未结 6 1538
小蘑菇
小蘑菇 2021-02-03 10:27

What type of transaction management strategy we should use in Spring? Declarative or Programmatic? Which one is better and under what situation one should use it? Can you give a

6条回答
  •  遇见更好的自我
    2021-02-03 11:21

    Programmatic Transaction Management

    1. Allows us to manage transactions through programming in our source code.
    2. This means hardcoding transaction logic between our business logic.
    3. We use programming to manage transactions
    4. Flexible, but difficult to maintain with large amount of business logic. Introduces boilerplate between business logic.
    5. Preferred when relative less transaction logic is to be introduced.

    Declarative Transaction Management

    1. Allows us to manage transactions through configuration.
    2. This means separating transaction logic with business logic.
    3. We use annotations (Or XML files) to manage transactions.
    4. Easy to maintain. Boilerplate is kept away from business logic.
    5. Preferred when working with large amount of Transaction logic.

提交回复
热议问题