当前位置:网站首页>解决启动项目初始化报错required a bean of type ‘int‘ that could not be found.的问题
解决启动项目初始化报错required a bean of type ‘int‘ that could not be found.的问题
2022-08-09 17:00:00 【一个想打代码的yebadi_】
报错信息
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-30 12:47:40.013 ERROR 24717 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.example.demo.service.UserService required a bean of type 'int' that could not be found.
Action:
Consider defining a bean of type 'int' in your configuration.
解决方法
给这个类添加上有参和无参构造器即可。
初因
本次博主是想测试项目的某个地方使用getbean而不是直接new 对象的原因以及产生的影响。
结论
最终发现单例bean与多例bean加载的不同,如果是单例bean,会在启动的时候加载出bean(这里默认是无参构造器),
如果是多例,那么会在使用的时候才构造出这个bean,当时只写了构造bean传递特定参数的构造器,然而自测的时候使用的是单例,导致初始化没有无参构造器引起报错,在此警惕。
初因收获
如果需要new出来的对象没有再次注入bean,可以直接new,否则得使用getbean的方式构造出,这样构造出来的对象中注入的bean才不会是null;
边栏推荐
猜你喜欢

一口气拿下6个大厂offer,是什么水平

The principle implementation of handwritten flexible.js, I finally understand the multi-terminal adaptation of the mobile terminal

WinForm(三)揭开可视化控件的面纱

Volatile:JVM 我警告你,我的人你别乱动

低代码平台和专业开发人员——完美搭档?
![[Pycharm easy to use function]](/img/f8/4c131516033286ba8bcb511d395462.png)
[Pycharm easy to use function]

ABP详细教程——模块类

Self-taught software testing, how far can I go out to find a job?

Ark: Survival Evolved Open Server Port Mapping Tutorial

总结篇4:redis 核心数据存储结构及核心业务模型实现应用场景
随机推荐
In-depth understanding of MySQL common data types and data type selection optimization
太细了!阿里大佬耗时39天整理出一份Redis进阶笔记,满满的干货
win10 uwp 绑定静态属性
动态RDLC报表(一)
在 .NET MAUI 中如何更好地自定义控件
微软 .NET Core 3.1 年底将结束支持,请升级到.NET 6
本机号码一键登录原理
神秘的程序员(20-30)
win10 uwp 模拟网页输入
试试使用 Vitest 进行组件测试,确实很香。
eyb:Redis学习(3)
【Pycharm好用功能】
逻辑越权和水平垂直越权支付篡改,验证码绕过,接口
方舟:生存进化开服务器端口映射教程
win10 uwp 活动磁贴
win10 uwp 装机必备应用 含源代码
win10 uwp 无法附加到CoreCLR
win10 uwp 让焦点在点击在页面空白处时回到textbox中
win10 uwp 获得Slider拖动结束的值
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)