'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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Krzysztof Tomaszewski |