当前位置:网站首页>解决启动项目初始化报错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;
边栏推荐
- 学长告诉我,大厂MySQL都是通过SSH连接的
- SkiaSharp 之 WPF 自绘 粒子花园(案例版)
- WinForm(三)揭开可视化控件的面纱
- Can't install the Vmware virtual machine on the Ark Kai server?
- uniapp电影购票选座系统源码
- mysql生成随机姓名、手机号、日期
- What is test development and why is it so popular now?
- [Code Audit] - PHP project class RCE and files include download and delete
- [SUCTF 2019]CheckIn
- 【代码审计】——PHP项目类RCE及文件包含下载删除
猜你喜欢

《ABP Framework 极速开发》 - 教程首发
In-depth understanding of MySQL common data types and data type selection optimization

重谈联想5G编码投票事件

【.NET6+Modbus】Modbus TCP协议解析、仿真环境以及基于.NET实现基础通信

.NET MAUI 跨平台应用开发 I|.NET MAUI 跨平台基础

Tan Zhongyi: Do you know who the "Queen of Open Source" is?

How tall is the B+ tree of the MySQL index?

Can't install the Vmware virtual machine on the Ark Kai server?

Discuz! Forum program installation + template configuration tutorial

一口气拿下6个大厂offer,是什么水平
随机推荐
好的架构是进化来的,不是设计来的
ABP详细教程——模块类
那些关于DOM的常见Hook封装(二)
Axure实现表格带滚动条
谭中意:你知道 “开源女王” 是谁吗?
Discuz! Forum program installation + template configuration tutorial
MASA Stack 第三期社区例会
微服务:事务管理
eyb:Redis学习(3)
为了高性能、超大规模的模型训练,这个组合“出道”了
基于ABP和Magicodes实现Excel导出操作
方舟:生存进化开服务器端口映射教程
在 C# 中如何检查参数是否为 null
太细了!阿里大佬耗时39天整理出一份Redis进阶笔记,满满的干货
.NET 6学习笔记(4)——解决VS2022中Nullable警告
WinForm(四)一种实现登录的方式
如何在 PC 机上测试移动端的网页?
字节也开始缩招了...
.NET Community Toolkit 8.0.0 版本发布
Apache Doris 社区 PMC 杨政国:开源项目如何在自身和社区的需求中取得平衡?