首页 > 其他分享 >The dependencies of some of the beans in the application context form a cycle

The dependencies of some of the beans in the application context form a cycle

时间:2022-12-02 15:47:20浏览次数:37  
标签:service form some application bean wongz com example

报错日志:

Description:
The dependencies of some of the beans in the application context form a cycle:
   personController (field com.example.wongz.service.UserService com.example.wongz.controller.PersonController.userService)
┌─────┐
|  UserServiceImplName (field com.example.wongz.service.impl.PersonService com.example.wongz.service.impl.UserServiceImpl.personService)
↑     ↓
|  personService (field private com.example.wongz.service.UserService com.example.wongz.service.impl.PersonService.userService)
└─────┘

报错原因:

两个类相互引用对方,导致Spring在初始化bean的时候不知道先初始化哪个,从而形成循环依赖注入。

解决方法:

1、其中一个不要引用对方,避免循环依赖

2、任选其中一个使用@Lazy 注解。

Spring在应用程序上下文启动时去创建所有的单例bean对象, 而@Lazy注解可以延迟加载bean对象,即在使用时才去初始化.

所以,@Lazy注解, 一是可以减少Spring的IOC容器启动时的加载时间, 二是可以解决bean的循环依赖问题

 

标签:service,form,some,application,bean,wongz,com,example
From: https://www.cnblogs.com/wongzzh/p/16944636.html

相关文章

  • 车载测试系列:自动驾驶中间件SOME/IP
    一、以太网引入汽车2004年,宝马汽车的OBD诊断口采用的是高速CAN总线,速率为500kbit/s,除去CAN协议本身的开销,通过OBD口升级控制器的净升级速度降到200kbit/s。预计到2008年,软......
  • application.yml与application.properties文件的相互转换、属性提取
    packagecom.liftsail.testprofiledemo.utiltest;importorg.springframework.util.CollectionUtils;importjava.util.*;/***@Author:liftsail*@Date:2022/......
  • CF 486C Palindrome Transformation
    题目给出一个字符串和光标所在位置,每次操作可以把光标向左,向右移动或者把当前字符串ASCII值+-1那么问变成回文的最小代价首先我们观察到,因为我们可以对字符串+或者-,所......
  • 后端接口要求请求头的Content-Type:application/x-www-form-urlencoded
    背景使用apipost接口请求工具调试后端接口的时候,后端要求的类型是application/x-www-form-urlencoded,采用其他方式无法获取到数据,前端如何发起网络请求呢?以类型为applica......
  • WebKitFormBoundary型POST怎么解决
    curl网站:https://curlconverter.com/  复制粘贴到下图红框中  然后使用生成的请求头和参数发起请求即可......
  • buuoj-[MRCTF2020]Transform
    1.winexe64bit无壳2.存在关键字符串3.ctrl+x跟踪找到程序主体4.浅浅分析+百度lobyte是啥一下5.脚本arr1=[0x67,0x79,0x7B,0x7F,0x75,0x2B,0x3C,0x52,......
  • vue2 数组18 some erver filter reduce axios
    some: return true是固定写法,终止some循环 erver: filter:   优化写法:arr.filter(item=>item.state).reduce((累加的结果,当前循环项)=>{},初始值)拿上......
  • test cpu performance with matrix multiplication
    一需求:测试cpu计算性能二方法:1.使用一定规模方阵执行乘法运算,不需要保存结果。2.根据CPU核数开启线程执行乘法运算3.事先将线程执行任务放入线程对应的任务容器,然后开启线......
  • insmod提示“Invalid module format”
    1.现象:编译usb驱动程序,提示2.原因:在不同机器上编译了驱动导致无效格式3.解决:在目标机器搭建好编译环境,执行编译内核操作即可makemakeinstallmodprobeusbnetinsmodXXX.kom......
  • Application总结
    通过Application来进行一些,数据传递,数据共享等,数据缓存等操作。当android程序启动时系统会创建一个application对象,用来存储系统的一些信息。通常我们是不需要指定一个Ap......