Bean lifecyclehard5-8 years

A production service's `@Transactional` method silently isn't transactional — no error, no exception, it just doesn't roll back on failure. The startup log has one `INFO` line: "Bean 'myService' of type [MyService] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)". What does that warning actually mean, and why does it happen?

It means exactly what it says: something forced myService to be constructed earlier than usual — before the post-processor responsible for wrapping beans in proxies (the one @Transactional relies on) had itself been registered — so myService never got wrapped. It compiles, it starts, it runs, and its @Transactional annotation is simply never read by anything, because the mechanism that reads it wasn't in place yet when myService was built. The usual cause is a @Bean method in a @Configuration class that also defines a BeanPostProcessor (or a post-processor) as a non-static @Bean — building that post-processor bean requires instantiating the whole configuration class first, which drags along anything else that configuration class happens to construct early, ahead of when auto-proxying infrastructure is ready.

The lesson behind it →
More on Bean lifecycle