Spring also allows us to use "autoproxy" bean definitions, which can automatically proxy selected bean definitions.
In the section about ProxyFactoryBean
, we saw how to use AOP in the classic way. But it's clear that writing seperately for each bean on which we want to apply an advisor is not a pleasant thing to see, especially if they are many. So let's consider it as a practicable way only if the beans to be configured in that modality are few.
On the other hand, if the beans to which we have to apply AOP are many, in order to avoid finding ourselves with very long configuration files, we adopt another tactic: We use the auto proxy creator system, which allows us to automatically create proxies for the beans and avoid using ProxyFactoryBean
.
There are two classes made available by Spring to allow the autoproxy creator: BeanNameAutoProxyCreator
and DefaultAdvisorAutoProxyCreator
.