Quick revision
The short answer
@Transactional on a private method has no effect because Spring applies transactions through a proxy, and a proxy can only intercept methods it can override or implement: a CGLIB subclass cannot override a private method, and a JDK interface proxy only has the interface's public methods. Since Spring Framework 6.0, class-based CGLIB proxies do apply @Transactional to protected and package-private methods, so those work when the call comes from another bean through the proxy. Interface-based JDK proxies still only see public interface methods, and final methods are never intercepted by CGLIB.
What to remember
In this answer, we saw that @Transactional works through a proxy, and a proxy can only intercept methods it can override or implement. Private methods are never intercepted. Since Spring Framework 6.0, CGLIB proxies apply @Transactional to protected and package-private methods, while JDK interface proxies still see only public interface methods. Final methods and classes cannot be proxied by CGLIB and can even fail with a NullPointerException. The fix is to put the transaction on a method called through the proxy, usually the public entry point, or to use TransactionTemplate.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@Transactional on a private method has no effect because Spring applies transactions through a proxy, and a proxy can only intercept methods it can override or implement: a CGLIB subclass cannot override a private method, and a JDK interface proxy only has the interface's public methods. Since Spring Framework 6.0, class-based CGLIB proxies do apply @Transactional to protected and package-private methods, so those work when the call comes from another bean through the proxy. Interface-based JDK proxies still only see public interface methods, and final methods are never intercepted by CGLIB.
Background to this question
This question looks like trivia about visibility modifiers, but it tests whether we understand how Spring adds behaviour to our code. It also changed in a recent major version, so an answer that was correct in 2019 is incomplete today. In this answer, we will recap how the transaction proxy works, reproduce the private-method case, see exactly why each visibility level does or does not work with each kind of proxy, look at the final-method trap, and end with what to do instead.
1A Quick Recap of the Transaction Proxy
When a bean has @Transactional methods, Spring does not change the class. After creating the bean, it wraps it in a proxy, a generated object that stands in front of our bean. Other beans are injected with the proxy. When they call a method, the proxy checks whether the method is transactional, starts a transaction if so, calls our real object (the target) and then commits or rolls back.
There are two kinds of proxy. A JDK dynamic proxy is a generated class that implements the bean's interfaces; it only has the methods those interfaces declare. A CGLIB proxy is a generated subclass of the bean's class; it overrides the bean's methods. Spring Boot uses CGLIB by default. Both kinds can only add behaviour to a method if they can put their own version of that method in front of ours.
2Reproducing the Private Method Case
Here is a service where the transactional work sits in a private helper. We log whether a transaction is active inside it.
There are really two reasons it fails here, and it is worth separating them. The call to move() is a self-call from inside the object, which never goes through the proxy anyway. But even if another bean could call move(), the proxy could not intercept it, because a private method cannot be overridden by a subclass. Spring does not report an error; the annotation is simply ignored. IntelliJ IDEA warns about it, which is a good reason to read IDE warnings on annotated methods.
3Why Each Visibility Level Behaves as It Does
A CGLIB proxy is a subclass, so it can override any method that a subclass in the same package could override: public, protected and package-private, but not private. Before Spring Framework 6.0, Spring's transaction attribute source deliberately looked only at public methods, so even protected and package-private methods were ignored. Since 6.0, for class-based proxies, Spring applies @Transactional to protected and package-visible methods too, which is useful for package-private service classes in a modular design.
A JDK dynamic proxy only implements interfaces, and interface methods are public. So with an interface proxy, only methods declared on the interface can be transactional; a protected or package-private method on the implementation class is invisible to the proxy.
| Method | CGLIB proxy (Spring 6+) | CGLIB proxy (Spring 5) | JDK interface proxy |
|---|---|---|---|
| public | Yes | Yes | Yes, if declared on the interface |
| protected | Yes | No | No |
| package-private | Yes | No | No |
| private | No | No | No |
| final (any visibility) | No | No | Only via the interface method |
| static | No | No | No |
Notice that the 6.0 change applies to @Transactional. Other proxy-based annotations follow their own rules, so for @Cacheable, @Async or security annotations on non-public methods, check your version's documentation before relying on it. In every case the call still has to come from outside the bean, through the proxy.
4The Final Method Trap
Final methods deserve a separate warning because they fail more strangely than private ones. A CGLIB subclass cannot override a final method, so the call runs the method on the proxy instance itself rather than on the target. The proxy instance is created without running our constructor, so its own fields are null. A final method that uses an injected field then throws a NullPointerException, which is confusing because the field is clearly injected in the target.
So the rule is simple: do not make proxied methods final, and do not make proxied classes final either, because CGLIB cannot subclass a final class at all. Kotlin classes are final by default, which is why the kotlin-spring compiler plugin opens classes annotated with Spring stereotypes.
5What to Do Instead
The clean fix for the original code is to make the transactional method part of a bean's public contract and call it from another bean. Here that means moving the transfer logic into its own transactional public method, or simply putting @Transactional on transfer() itself, since it is the entry point that should define the transaction. If we need transactional work inside a private helper, TransactionTemplate lets us start the transaction explicitly in code, which works regardless of visibility or self-calls.
6Follow-up questions
Why did Spring originally restrict @Transactional to public methods?
Partly because JDK proxies can only expose public interface methods, so public-only gave the same behaviour for both proxy types, and partly as a design statement that transaction boundaries belong to a bean's public API. Spring 6 relaxed it for class-based proxies because package-private service classes became more common.
Would AspectJ mode make a private @Transactional method work?
Yes. With @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) and AspectJ weaving, the advice is woven into the class's bytecode, so private methods and self-calls are both transactional. The cost is setting up compile-time or load-time weaving.
Does Spring log a warning when it ignores the annotation?
Generally no. The annotation is just not found by the proxy's matching, so nothing happens and nothing is logged. IDE inspections and ArchUnit rules are the practical ways to catch it.
7Conclusion
In this answer, we saw that @Transactional works through a proxy, and a proxy can only intercept methods it can override or implement. Private methods are never intercepted. Since Spring Framework 6.0, CGLIB proxies apply @Transactional to protected and package-private methods, while JDK interface proxies still see only public interface methods. Final methods and classes cannot be proxied by CGLIB and can even fail with a NullPointerException. The fix is to put the transaction on a method called through the proxy, usually the public entry point, or to use TransactionTemplate.
Open with
It has no effect because Spring applies @Transactional with a proxy, and a proxy can only intercept a method it can override or implement. A CGLIB proxy is a subclass, and a subclass cannot override a private method, so the annotation is silently ignored.
Then, if they want more
In the usual case there is a second reason as well: the private method is called from inside the same class, which is a self-call on this and never goes through the proxy. For protected and package-private methods the answer depends on the version and the proxy type.
Since Spring Framework 6.0, class-based CGLIB proxies, which Spring Boot uses by default, do apply @Transactional to protected and package-visible methods, as long as the call comes from another bean through the proxy. Before 6.0 only public methods were considered. With an interface-based JDK proxy, only methods on the interface can be intercepted, and those are public.
I would also mention final methods: CGLIB cannot override them, so the call runs on the proxy instance, whose fields are null, and you can get a NullPointerException. The fix is to put @Transactional on the public entry method that should own the transaction, or to use TransactionTemplate when I need the boundary inside the class.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "@Transactional on a private method has no effect. Why? Would it work on a protected or...": https://scrivio-interview-library.netlify.app/spring-boot/aop/5c1154ed1c/