简体   繁体   中英

Spring proxy: BeanPostProcessor or AOP?

We can create proxy for the target bean in the postProcessAfterInitialization() method of BeanPostProcessor.

Or we can use AOP - and proxy will also be created through Dynamic Proxy or CGlib.

What is the difference?

When should we use BPP and when AOP?

As far as I know bean-post-processor is a more powerful tool. It can complete replace the bean (so you can even shoot in your own foot). On the other hand AOP approach has very handy pattern matching solution. In a bean-post-processor approach you get an Object and you have to recognize what is its type. Moreover AOP approach is more about adding a behaviour related to pattern-selected methods' execution. With bean-post-processor you can replace (or just modify) a whole bean which possibly affects all of its method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM