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

关于 Spring 循环依赖的问题

  •  
  •   wozhidaole · 54 天前 · 1954 次点击
    这是一个创建于 54 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近发现一个问题

    Linux 服务器通过 maven 打出来的部分项目,部署的时候会出现循环依赖报错 但是同样的代码,在 Windows 机器上打出来的 jar 包,部署在相同服务器上不会有循环依赖的报错 没有问题的项目中,也有部分存在循环依赖,但是也能正常部署,只有极个别的项目有上述的问题。

    springboot 版本 2.0.5 jdk 1.8

    Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'applyServiceImpl': Bean with name 'applyServiceImpl' has been injected into other beans [contractServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example

    8 条回复    2024-03-04 19:09:05 +08:00
    suwu
        1
    suwu  
       54 天前
    给个 dome ?
    BBCCBB
        2
    BBCCBB  
       54 天前
    这个说不准的, 和他的加载顺序也有关系..
    有时候不同的机器可能就会出现.. A 机器没问题, B 机器可能就出现了.

    要么梳理代码, 避免循环依赖, 不过这个一般不可能, 要么就是 @Lazy 大法..
    yichengxian
        3
    yichengxian  
       54 天前   ❤️ 3
    你这个啊 @Lazy 大法好啊
    nodododo
        4
    nodododo  
       54 天前   ❤️ 1
    我记得我也遇到过,就是运行环境的加载顺序问题,因为 win 和 linux 的路径是不一样的,所以加载顺序导致了循环依赖的出现
    hengyunabc
        5
    hengyunabc  
       54 天前
    升个高版本点的 spring boot 应该可以解决,它会保存依赖 jar 的顺序,避免不同环境加载 jar 顺序不一致。
    imzhoukunqiang
        6
    imzhoukunqiang  
       54 天前 via Android
    是不是用了 @Async 注解?
    ychost
        7
    ychost  
       54 天前
    这很正常的,代码里面循环依赖加个 Lazy 吧,我也遇到过本地能启动线上报错的情况,Spring 对 Bean 的加载 顺序是不定的
    bsg1992
        8
    bsg1992  
       54 天前
    循环依赖这种情况 就应该避免。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1414 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:13 · PVG 01:13 · LAX 10:13 · JFK 13:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.