Instantiation of beans (6) cyclic dependencies

teasers

At this point, bean instantiation is nearing its end, IOC is done, and aop, the other core of Spring, is next. Spring AOP is dependent on IOC for management.

Early AOP

Before annotations, Spring’s functionality was implemented through configuration, and early AOP was no exception, with three configurations. Rather than describing a long theory, spring AOP can simply be understood as an enhancement to existing methods.

Interface-based Configuration

This approach was introduced in Spring 1.2, the earliest AOP.

Advice way

  1. Define the classes that need to be enhanced

  1. Defining advice (enhanced)

  1. Configure enhancements to apply to the target method

  1. Invoke the proxy object enhancement method

Interceptor way

  1. Defining interceptors

  1. Configure enhancements to apply to the target method

Both approaches are the same in that they implement the Advice interface

Advisor way

Advice, Interceptor scope all methods in a class, do not specify methods. This introduces the concept of Advisor. Advisors can specify Advice and target methods:

  1. Specify proxy objects and enhancements

  1. Create Advisor and proxy objects

At this point, we can implement the enhanced specification, but we need to create proxy objects for each class and then directly retrieve them when using beans. The functionality is there, but the cost is high.

Autoproxy is automatically configured

BeanNameAutoProxyCreator

  1. Specify proxy objects and enhancements

  1. Create AutoProxyCreator

Instead of manually generating the proxy object, the name of the proxy object changes to the bean name of the target object.

RegexpMethodPointcutAdvisor

  1. Specify proxy objects and enhancements

  1. Create RegexpMethodPointcutAdvisor

However, this approach does not specify methods

conclusion

Spring as of version 1.2 set up proxies through the interface + ProxyFactoryBean.

Note: this article through the source code + line description of the way to describe, if not understand can leave a message. This article is only a personal learning record, there are mistakes, please correct.