最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

sping循环依赖:but has eventually been wrapped. This means that said other beans do not use the final

常识 admin 34浏览 0评论

sping循环依赖:but has eventually been wrapped. This means that said other beans do not use the final

今天写代码的时候遇到一个报错
 

nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'A': Bean with name 'A' has been injected into other beans [B] 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

经过科学上网排查,发现是spring 循环依赖了。如:

@Component
public class ServiceA {

    @Autowired
    private ServiceB serviceB;

    public ServiceA() {
        System.out.println("init serviceA");
    }
}

 



@Component
public class ServiceB {

    @Autowired
    ServiceA serviceA;

    public ServiceB() {
        System.out.println("innit ServiceB");
    }
}

互相依赖于对方,实例化时导致报错。

解决:我目前并没有解决循环依赖的问题,而是避免循环依赖。

如何解决sping的循环依赖,待定。

sping循环依赖:but has eventually been wrapped. This means that said other beans do not use the final

今天写代码的时候遇到一个报错
 

nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'A': Bean with name 'A' has been injected into other beans [B] 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

经过科学上网排查,发现是spring 循环依赖了。如:

@Component
public class ServiceA {

    @Autowired
    private ServiceB serviceB;

    public ServiceA() {
        System.out.println("init serviceA");
    }
}

 



@Component
public class ServiceB {

    @Autowired
    ServiceA serviceA;

    public ServiceB() {
        System.out.println("innit ServiceB");
    }
}

互相依赖于对方,实例化时导致报错。

解决:我目前并没有解决循环依赖的问题,而是避免循环依赖。

如何解决sping的循环依赖,待定。

发布评论

评论列表 (0)

  1. 暂无评论