V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lxk11153
V2EX  ›  Java

Spring Framework: earlySingletonObjects 如何配置里面会写入东西?

  •  
  •   lxk11153 · 2019-11-20 18:58:11 +08:00 · 2270 次点击
    这是一个创建于 1590 天前的主题,其中的信息可能已经有所发展或是发生改变。

    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#earlySingletonObjects

    找了个项目跑了一遍,没看到里面写入东西过~ 0==modCount

    第 1 条附言  ·  2019-11-20 20:16:29 +08:00
    1. 和它有关吗?DefaultListableBeanFactory#getBeansOfType(Class<T>, boolean, boolean)

      allowEagerInit whether to initialize lazy-init singletons and objects created by FactoryBeans (or by factory methods with a "factory-bean" reference) for the type check. Note that FactoryBeans need to be eagerly initialized to determine their type: So be aware that passing in "true" for this flag will initialize FactoryBeans and "factory-bean" references.

    2. 两者有关系吗?

    第 2 条附言  ·  2019-11-20 22:59:13 +08:00

    不好意思,看错了!既然提到了也索性问下 allowEagerInit 这个拿来干嘛的?

    4 条回复    2019-12-04 10:38:00 +08:00
    skypyb
        1
    skypyb  
       2019-11-20 19:03:27 +08:00
    这玩意我没记错的话是解决循环依赖的。
    你搞几个 Bean 互相依赖试试
    lxk11153
        2
    lxk11153  
    OP
       2019-11-20 22:47:29 +08:00
    see docs.spring.io
    1. `Setter-based Dependency Injection` 和 `Annotation-based Container Configuration`(@Resource ...)
    ---- earlySingletonObjects 就是解决它俩的循环依赖的
    2. `Constructor-based Dependency Injection`
    ---- 它的循环依赖得调整自己的代码
    3. allowEagerInit
    ---- 不知道
    lxk11153
        3
    lxk11153  
    OP
       2019-11-21 17:12:12 +08:00
    allowEagerInit ? 还是不知道区别在哪
    https://blog.csdn.net/zknxx/article/details/80822352
    lxk11153
        4
    lxk11153  
    OP
       2019-12-04 10:38:00 +08:00
    2. `Constructor-based Dependency Injection`
    ---- 它的循环依赖得调整自己的代码 see: blog.csdn.net/Revivedsun/article/details/84642316
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3130 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:28 · PVG 22:28 · LAX 07:28 · JFK 10:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.