Quick revision
The short answer
No transaction starts for two reasons. @PostConstruct runs during the bean's initialisation, before postProcessAfterInitialization, so the AOP proxy that adds transactions does not exist yet; and the call is a self-invocation on this, which never goes through a proxy anyway. The fix is to call the method through a proxy, from a different bean or from an ApplicationReadyEvent listener, or to manage the transaction in code with TransactionTemplate, and to keep heavy work out of @PostConstruct because it blocks startup.
What to remember
In this answer, we saw that a @Transactional method called from @PostConstruct gets no transaction for two reasons: @PostConstruct runs before postProcessAfterInitialization, so the transactional proxy does not exist yet, and the call goes to this, which never passes through a proxy. We fixed it by triggering the work from another bean, by making the transactional method an ApplicationReadyEvent listener that Spring calls through the proxy, or by using TransactionTemplate, and we saw why heavy work does not belong in @PostConstruct at all.
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.
No transaction starts for two reasons. @PostConstruct runs during the bean's initialisation, before postProcessAfterInitialization, so the AOP proxy that adds transactions does not exist yet; and the call is a self-invocation on this, which never goes through a proxy anyway. The fix is to call the method through a proxy, from a different bean or from an ApplicationReadyEvent listener, or to manage the transaction in code with TransactionTemplate, and to keep heavy work out of @PostConstruct because it blocks startup.
Why this question is asked
This is one of the most common surprises in Spring: we load reference data at startup in a @PostConstruct method, mark the loader @Transactional, and then find lazy-loading exceptions or partial writes because no transaction ever started. Interviewers like it because the explanation needs two separate ideas, the bean lifecycle and how proxies work, and a good answer names both. In this answer, we will recap how @Transactional works, reproduce the problem, explain it with the lifecycle, explain the self-invocation part, and go through three fixes.
1A Quick Recap of How @Transactional Works
@Transactional does nothing by itself; it is just an annotation. Spring makes it work by creating a proxy, a wrapper object generated at runtime that has the same type as our bean. When another bean calls a method on the proxy, the proxy asks the transaction manager to begin a transaction, calls our real method, and then commits or rolls back.
Two facts follow. First, the proxy has to exist, and Spring creates it during the bean lifecycle, in the BeanPostProcessor step called postProcessAfterInitialization. Second, the call has to go through the proxy. A call from one method of our class to another method of the same class goes to this, the raw object, and the proxy never sees it.
2Reproducing the Problem
Here is a service that loads countries into a cache at startup. The loader method is transactional, and we print whether a transaction is active.
Notice that the same method prints false at startup and true when a controller calls it. The method and the annotation are the same; what differs is the path the call takes.
3Why the Lifecycle Explains the First Half
Spring creates a singleton in a fixed order. It calls the constructor, injects fields and setters, runs the Aware callbacks, then runs postProcessBeforeInitialization on every BeanPostProcessor, which is where @PostConstruct is called. Only after that, in postProcessAfterInitialization, does the auto-proxy creator wrap the bean in its transactional proxy.
So while init() is running, the proxy does not exist at all. Spring is still working on the raw CountryCache object, and nobody has wrapped it yet. Even if we tried to look up the bean from the context inside init(), we would not get a proxy, because the bean is still in creation.
- Constructorrepo injected
- Populate fields and setters
- BPP before initialization
init()runs here,reload()on the raw object - BPP after initializationtransactional proxy created
- Bean readycallers now get the proxy
5 steps in order. Play them, or step through them one at a time.
4Why Self-Invocation Explains the Second Half
Suppose Spring did create the proxy earlier. The call would still not be transactional, because init() calls reload() as this.reload(). The proxy is a separate object that holds a reference to our bean; when code inside the bean calls one of its own methods, the call stays inside the bean and never passes the proxy. This is the same reason a @Transactional method called from another method of the same class, at any time, gets no new transaction.
So there are two independent problems, and a fix has to solve both: the call must happen after the proxy exists, and it must come from outside the bean, through the proxy.
5Fix 1: Call It From Another Bean
The clearest fix is to move the startup trigger into a different bean. Constructor-injected dependencies are fully initialised before they are injected, including their proxy, so the other bean receives the proxy and its call is transactional.
Notice that we also moved the work from @PostConstruct to ApplicationReadyEvent, which Spring Boot publishes when the application has fully started. That keeps startup fast and lets the cache load when every bean, including the transaction manager and the data source, is ready. A @PostConstruct in CountryCacheLoader would also work, because the injected cache is already a finished proxy, but the event is the better habit.
6Fix 2: An Event Listener on the Bean Itself
We can also keep everything in one class by making the transactional reload() method itself the listener. Spring invokes @EventListener methods on the bean it gets from the context, which is the proxy, so the transaction starts.
Notice that the @PostConstruct method is gone. The event arrives after the context is complete, Spring calls the listener through the proxy, and so both problems are solved by one change. The cost is that the class now mixes its cache logic with its startup trigger, which is fine for small classes and a reason to prefer the separate loader bean in larger ones.
7Fix 3: TransactionTemplate, and Keeping @PostConstruct Light
If the work really must happen during initialisation, we can manage the transaction in code with TransactionTemplate, which does not depend on a proxy at all.
This works, but think about what it means. Everything in @PostConstruct runs on the startup thread while the context is being built. A slow query here delays the whole application, and an exception here fails the whole startup. For a few hundred countries that may be fine. For a large cache or a remote call, loading after startup on ApplicationReadyEvent, with readiness waiting for it if needed, is the safer design.
8Follow-up questions
Would making reload() private or protected change anything?
It would make things worse in general. Spring's transactional proxies only apply @Transactional to methods the proxy can intercept; by default only public methods are considered, and since Spring Framework 6 protected and package-visible methods on class-based proxies are supported too (check your version). Private methods are never intercepted, and the self-invocation problem remains in every case.
Does AspectJ weaving solve the self-invocation problem?
Yes. With AspectJ mode, the transactional code is woven into the class itself at compile or load time, so even this.reload() is transactional. It needs extra build or agent setup, so most teams prefer moving the call to another bean.
Is injecting the bean into itself with @Lazy a fix?
It works after startup, because calls through the injected proxy are transactional, but in @PostConstruct the proxy target is still the bean in creation, so it is fragile there. A separate bean or an event listener is clearer.
9Conclusion
In this answer, we saw that a @Transactional method called from @PostConstruct gets no transaction for two reasons: @PostConstruct runs before postProcessAfterInitialization, so the transactional proxy does not exist yet, and the call goes to this, which never passes through a proxy. We fixed it by triggering the work from another bean, by making the transactional method an ApplicationReadyEvent listener that Spring calls through the proxy, or by using TransactionTemplate, and we saw why heavy work does not belong in @PostConstruct at all.
Open with
There are two reasons, and both come from how Spring applies @Transactional through a proxy. First, the lifecycle: @PostConstruct is called in the postProcessBeforeInitialization step, and the auto-proxy creator only wraps the bean in its transactional proxy later, in postProcessAfterInitialization.
Then, if they want more
So while the init method runs, there is no proxy at all; Spring is still working on the raw object. Second, even if the proxy existed, the call is this.reload(), a self-invocation, and a call inside the object never passes through the proxy.
I can show it with TransactionSynchronizationManager.isActualTransactionActive, which prints false at startup and true when a controller calls the same method. To fix it, I make the call come from outside, after the proxy exists. My first choice is a small loader bean that injects the service, which is already a finished proxy, and calls it on ApplicationReadyEvent.
Or I put @EventListener for ApplicationReadyEvent directly on the transactional method, since Spring calls listeners through the proxy. If it really has to happen during initialisation, I use TransactionTemplate. I would also keep @PostConstruct light, because slow work there blocks the whole context startup.
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 "A @PostConstruct method calls a @Transactional method on the same bean and no...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/8e52cd27d6/