2V0-72.22PSE · Question #37
Which two are required to use transactions in Spring? (Choose two.)
The correct answer is A. Add @EnableTransactionManagement to a Java configuration class. B. Annotate a class, an interface, or individual methods requiring a transaction with the. Enabling transactions in Spring requires two things working together: A activates the Spring transaction infrastructure by telling Spring to look for @Transactional annotations and proxy the appropriate beans, while B marks which classes, interfaces, or methods should actually…
Question
Which two are required to use transactions in Spring? (Choose two.)
Options
- AAdd @EnableTransactionManagement to a Java configuration class.
- BAnnotate a class, an interface, or individual methods requiring a transaction with the
- CA class must be annotated with @Service and @Transaction.
- DA class requiring a transaction must implement the TransactionInterceptor interface.
- EWrite a Spring AOP advice to implement transactional behavior.
How the community answered
(46 responses)- A91% (42)
- C4% (2)
- D2% (1)
- E2% (1)
Explanation
Enabling transactions in Spring requires two things working together: A activates the Spring transaction infrastructure by telling Spring to look for @Transactional annotations and proxy the appropriate beans, while B marks which classes, interfaces, or methods should actually be wrapped in a transaction - without both, either the infrastructure isn't running or nothing is targeted.
Why the distractors are wrong:
- C is wrong because
@Serviceis unrelated to transactions;@Transactionalalone (not@Transaction) is what marks transactional behavior, and it doesn't require@Service. - D is wrong because
TransactionInterceptoris an internal Spring mechanism you never implement directly - Spring does that for you via AOP under the hood. - E is wrong because writing your own AOP advice is the old, manual way;
@EnableTransactionManagement+@Transactionalreplaces that entirely with declarative transaction management.
Memory tip: Think of it as a two-key ignition - @EnableTransactionManagement is the engine (turns on the transaction system), and @Transactional is the key (tells Spring which code to actually protect with a transaction). You need both keys to start the car.
Topics
Community Discussion
No community discussion yet for this question.