当前位置:网站首页>解决启动项目初始化报错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;
边栏推荐
- How to choose a good SaaS knowledge base tool?
- 自学软件测试,学到什么程度可以出去找工作啊?
- Self-taught software testing, how far can I go out to find a job?
- win10 uwp 模拟网页输入
- Metasploit——辅助模块(Auxiliary)
- 在 C# 中如何检查参数是否为 null
- leetcode/链表中环的入口节点
- In-depth understanding of MySQL common data types and data type selection optimization
- 【.NET6+Modbus】Modbus TCP协议解析、仿真环境以及基于.NET实现基础通信
- 搭建Zabbix监控系统
猜你喜欢
随机推荐
《ABP Framework 极速开发》 - 教程首发
win10 uwp 活动磁贴
CPU状态信息us,sy,ni,id,wa,hi,si,st含义
总结篇4:redis 核心数据存储结构及核心业务模型实现应用场景
字符设备的注册
一口气拿下6个大厂offer,是什么水平
字节也开始缩招了...
mysql generates random name, mobile number, date
leetcode/链表中环的入口节点
win10 uwp 自定义控件 SplitViewItem
怎样选择一个好的SaaS知识库工具?
进行知识管理的好处有哪些?
论如何提升学习的能力
win10 uwp 模拟网页输入
动态RDLC报表(一)
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
An in-depth understanding of the implementation principle of Hybrid
JMeter notes 6 | JMeter recording agent (configuration)
One-key login principle of local number
openEuler Xiong Wei: How do you view the SIG organization model in the open source community?



![[SUCTF 2019]CheckIn](/img/4a/cae4dbe47c3b9d0fb37fe337bb5c3f.png)



![[极客大挑战 2019]HardSQL](/img/99/74cd7c56b3915db371ebc7811f2987.png)

