nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #63

Using the default configurations, which methods will be affected when adding the @Transactional annotation to the class?

The correct answer is A. public methods. When @Transactional is placed on a class in Spring, it applies to all public methods of that class by default, because Spring's transaction management relies on proxy-based AOP (either JDK dynamic proxies or CGLIB), and these proxies can only intercept public method calls from…

Data Access

Question

Using the default configurations, which methods will be affected when adding the @Transactional annotation to the class?

Options

  • Apublic methods
  • Bprotected methods
  • Cprivate methods
  • D@Transactional may be used only on methods

How the community answered

(37 responses)
  • A
    92% (34)
  • C
    3% (1)
  • D
    5% (2)

Explanation

When @Transactional is placed on a class in Spring, it applies to all public methods of that class by default, because Spring's transaction management relies on proxy-based AOP (either JDK dynamic proxies or CGLIB), and these proxies can only intercept public method calls from outside the bean.

Why B and C are wrong: Protected and private methods are not visible to Spring's proxy mechanism - they are called directly on the target object, bypassing the proxy entirely, so no transactional behavior is applied.

Why D is wrong: @Transactional can be placed at the class level (not just on methods); doing so is a shorthand that applies the annotation to all eligible (public) methods, rather than annotating each one individually.

Memory tip: Think of Spring's proxy as a "doorman" standing outside the class - it can only intercept guests (calls) coming through the public entrance. Private and protected side doors are invisible to the doorman, so those methods slip through without transactional wrapping.

Topics

#@Transactional#AOP Proxies#Transaction Boundaries#Method Visibility

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice