Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameter 标签: 构造器注入Spring
问题:要么是因为构造方法改变了,要么就是构造方法入参实例化失败(比如没有实现)
问题
在练习spring构造器注入方式的小程序的时候报错:
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘poeticDuke’ defined in class path resource [com/springinaction/springidol/spring-idol.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
原因和解决方法
报错信息大体是说创建poeticDuke这个bean的时候出错,出错的原因是与构造器不匹配,给出的线索是为bean的构造器参数指定正确的索引、类或者名字,防止引起混淆。
构造器方法如下:
public PoeticJuggler(int beanBags, Poem poem) {
super(beanBags);
this.poem = poem;
}
XML配置文件如下:
<bean id="sonnet29" class="com.springinaction.springidol.Sonnet29" />
<bean id="poeticDuke" class="com.springinaction.springidol.PoeticJuggler">
<constructor-arg value="15" />
<constructor-arg ref="sonnet29" />
</bean>
报错信息说参数不匹配,猜测应该是指constructor-arg元素内的参数类型不匹配,这里”15”和”sonnet29”应当分别对应于int原始数据类型和Poem类,15肯定是int类型这没问题,那么再看sonnet29,它是类Sonnet29的bean,然后我去看类Sonnet29是怎么写的,才发现忘记去实现Poem接口了,然后加上接口,程序正常。
public class Sonnet29 implements Poem {/*Here goes body.*/}
Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameter 标签: 构造器注入Spring的更多相关文章
- akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
在spark-shell中输入范例中的代码: import akka.actor.Actor import akka.actor.Props import akka.event.Logging cla ...
- hint指定index的深入理解
http://czmmiao.iteye.com/blog/1480247创建一个表,含有位图index和b-tree index SQL> create table t as select o ...
- Effective Java Item3:Enforce the singleton property with a private constructor or an enum type
Item3:Enforce the singleton property with a private constructor or an enum type 采用枚举类型(ENUM)实现单例模式. ...
- Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor
Newtonsoft.Json DeserializeObject 反序列化 IdentityServer4.Models Cliecnt 错误: Newtonsoft.Json.JsonSeria ...
- 【Elasticsearch】清空指定index/type下的数据
1.postman请求接口 http://ip:端口/index/type/_delete_by_query?conflicts=proceed body为: { "query": ...
- mysql index hint 在index不存在时的处理
关于index_hint 在mysql查询语句中可以通过指定index_hint来告诉优化器如何使用索引,详细可以参考这里 index_hint: USE {INDEX|KEY} [FOR {JOIN ...
- WCDB错误"No matching constructor for initialization of 'WCTColumnBinding'"
开始看到这个错误有点匪夷所思,完全不知道问题指向哪里, 最后用过排除法,把之前建立多个类进行了一一排除,发现有个属性是 @property(nonatomic, assign) NSInteger * ...
- Effective Java 03 Enforce the singleton property with a private constructor or an enum type
Principle When implement the singleton pattern please decorate the INSTANCE field with "static ...
- 常见Hibernate报错处理:出现“org.hibernate.QueryException: could not resolve property”和 is not mapped和could not locate named parameter错误的解决
正确写法: @Override @SuppressWarnings("unchecked") public List<Device> queryOSDevice(Str ...
随机推荐
- javascript runat server
<script runat="server"> protected void SubmitBtn_Click(object sender, EventArgs e) { ...
- SQL Server服务器连接配置
一.首先确保服务器能在本地打开数据库 如果碰到本地无法连接到数据库,首先要确认上图中两个服务是否开启 二.其次,要配置远端可连接的用户 如图,配置数据库[属性]中[安全性]为混合验证,勾中允许远程连接 ...
- Linux which 查找命令
在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 权限管理命令: which 基础的命令 命令名称:which 命令的所在路径:/usr/bin ...
- 洛谷 - P2568 - GCD - 欧拉函数
https://www.luogu.org/problemnew/show/P2568 统计n以内gcd为质数的数的个数. 求 \(\sum\limits_p \sum\limits_{i=1}^{n ...
- 使用fastadmin的页面跳转模板
1.效果图 2.修改tp默认跳转模板文件( /thinkphp/tpl/dispatch_jump.tpl ),将文件中的内容全部替换成下面的内容然后保存即可,注意替换语言包和图片路径 {__NOLA ...
- PHP 数组序列化,转为字符串
serialize() <?php $a = array('a' => 'as' ,'b' => 'bs' , 'c' => 'cs'); //序列化数组 $s = seria ...
- Python 3.x 的一些注意事项
1. reload 被更改 需要 在console执行 from imp import reload 才能调用CT 同时,如果py文件是位于主文件夹深部的位置,可以这么做: import ComicT ...
- 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration
现在大部分的Spring项目都采用了基于注解的配置,采用了@Configuration 替换标签的做法.一行简单的注解就可以解决很多事情.但是,其实每一个注解背后都有很多值得学习和思考的内容.这些思考 ...
- VLAN-3-VLAN Trunk:ISL和802.1Q
(1)ISL和802.1Q概念 通过使用VLAN Trunk链路,设备可以通过一条链路发送去往多个vlan的流量.为了知道数据帧属于哪个vlan,发送方会添加原始以太网数据帧的头部,这 ...
- 【bzoj1726】Roadblocks
1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1578 Solved: 795[ ...