Giter VIP home page Giter VIP logo

Comments (4)

Linweixinyo avatar Linweixinyo commented on May 11, 2024 1

@jaxlove 我不知道我理解的对不对,我认为你应该是在困惑(在初始化完成之后执行postProcessAfterInitialization可能会对原有的Bean进行代理,但是在mini-spring中初始化完成之后调用了getSingleton(beanname)导致触发三级缓存中创建代理的流程,导致原有的代理被覆盖)。其实在spring源码中getSingleton方法还有一个boolean类型的变量boolean allowEarlyReference来控制最多查询到二级缓存,这样就可以避免触发三级缓存中的提前创建代理。以上是我的看法,希望能够对你有所帮助,可以等待原作者的回答

from mini-spring.

niuxvdong avatar niuxvdong commented on May 11, 2024

@jaxlove 可以看到作者在 DefaultAdvisorAutoProxyCreator 中增加了一个 earlyProxyReferences 标记,用来判断这个代理对象问题。创建过则不会再次创建。可以看我写的说明,希望对你有帮助:https://github.com/niuxvdong/small-spring/blob/master/small-spring-16/README.md#6%E5%A2%9E%E5%8A%A0-getearlybeanreference-%E5%AE%9E%E7%8E%B0
其实可以通过 debug 来查看一下整个执行流程来帮助理解。

from mini-spring.

DerekYRC avatar DerekYRC commented on May 11, 2024

@jaxlove @Linweixinyo 如下图,AbstractAutowireCapableBeanFactory#doCreateBean方法中创建bean后,如果存在代理,则将代理bean放进三级缓存,否则将原始bean放进三级缓存。initializeBean方法入参的bean是原始bean,注意不是代理bean。最后从三级缓存中获取bean,由于是查询缓存,所以不会创建一个新的bean。
image

from mini-spring.

DerekYRC avatar DerekYRC commented on May 11, 2024

@jaxlove 建议debug对应单测加深理解

from mini-spring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.