AOP complements Dependency Injection to enable Spring to provide a non-invasive programming model. The two technologies complement each other perfectly.
Spring offers two flavors of AOP support: its own proxy-based AOP framework, which works in standard Java; and integration with specialized AOP technologies, especially AspectJ, the most mature AOP technology available.
We recommend using Spring AOP for most AOP requirements. It is particularly well suited for applying crosscutting behavior to business objects.
We recommend the following best practices:
Code duplication is a code smell. Avoid it. AOP can be a powerful tool to help avoid code duplication.
Remember that used correctly, AOP can significantly simplify application objects, and enable them to focus on their core responsibilities.
Minimize dependency on Spring framework APIs when using Spring AOP, as when using Spring in general.
If something clearly benefits from AOP, yet it's hard to do using Spring AOP (like advising fine- grained objects), consider using AspectJ.
When using ProxyFactoryBean, in most cases use an "inner bean" to ensure that autowiring works correctly and your factory namespace isn't polluted by two beans (proxy and target) when you really want just one (the proxy).
Familiarize yourself with the Spring "autoproxy" infrastructure. Particularly if you need to advise a large number of objects, this can produce significant simplification in application configuration.
Use bean definition "inheritance" as another technique to eliminate duplication of interceptor chain definitions and other AOP configuration.
If you can, use J2SE dynamic proxies rather than CGLIB, and access proxied objects only through their interfaces.
You can use AOP with confidence in your Spring applications: Many users already do, and AOP is the enabling technology for much of Spring's infrastructure functionality, such as declarative transaction management and lightweight remoting.