Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring - beans lifecycle

Tags:

java

spring

I have several configured beans in my spring application. All the beans working as it supposed to work and doing their jobs.

The thing is, I implemented a BeanPostProcessor and noticed that it isn't being called for some of the beans, (neither postProcessAfterInitialization nor postProcessBeforeInitialization). What could be the cause ?

like image 524
john Smith Avatar asked Dec 03 '25 06:12

john Smith


1 Answers

I don't know if it is relevant, but the reference manual says:

BeanPostProcessors and AOP auto-proxying

Classes that implement the BeanPostProcessor interface are special, and so they are treated differently by the container. All BeanPostProcessors and their directly referenced beans will be instantiated on startup, as part of the special startup phase of the ApplicationContext, then all those BeanPostProcessors will be registered in a sorted fashion - and applied to all further beans. Since AOP auto-proxying is implemented as a BeanPostProcessor itself, no BeanPostProcessors or directly referenced beans are eligible for auto-proxying (and thus will not have aspects 'woven' into them.

For any such bean, you should see an info log message: “Bean 'foo' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)”.

So, maybe your beans are being proxied.

like image 185
Luciano Avatar answered Dec 05 '25 21:12

Luciano