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 ...
随机推荐
- Spring入门(四):使用Maven管理Spring项目
让我们先回顾下本系列的前3篇博客: Spring入门(一):创建Spring项目 Spring入门(二):自动化装配bean Spring入门(三):通过JavaConfig装配bean 1.为什么要 ...
- [开源]OSharpNS - .net core 快速开发框架 - 快速开始
什么是OSharp OSharpNS全称OSharp Framework with .NetStandard2.0,是一个基于.NetStandard2.0开发的一个.NetCore快速开发框架.这个 ...
- 如何在html中引入jsx文件
不使用webpack工具做react项目 1.引入react相关js文件 <script src="https://cdn.staticfile.org/react/16.4.0/um ...
- phpstrom安装bootstrap3插件
1.步骤 File > > Settings > >Plugins > > 搜索bootstrap 3 然后点击 Browse repositories 就会有一个 ...
- PL/SQL 的 事务处理
原文连接 http://blog.csdn.net/lhl6688/article/details/42874109 BEGIN DECLARE V_COUNT INTEGER; -- 表中记录 ...
- 玲珑OJ1088【蜜汁尺取】
前言(膜法): 早上10点多开始膜的,然后到中午交了一发,感觉膜法不对啊!然后就兴起小窗了一发管理员,然后管理员给我发了in,out数据...可是太大并没有什么可取性... 还是自己试,然后发现自己搞 ...
- 51nod1010【二分】
打表+二分 #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL inf=1e18+10 ...
- [Xcode 实际操作]二、视图与手势-(12)UITapGestureRecognizer手势之双击
目录:[Swift]Xcode实际操作 本文将演示使用视图的双击手势,完成视图的交互功能. import UIKit class ViewController: UIViewController { ...
- jstl标签库不起作用,直接输出表达式
引用jstl.jar包 在jsp页面添加<%@ page isELIgnored="false"%>即可
- 使用JRegex抽取网页信息
当网络爬虫将网页下载到磁盘上以后,需要对这些网页中的内容进行抽取,为索引做准备.一个网页中的数据大部分是HTML标签,索引肯定不会去索引这些标签.也就是说,这种信息是没有用处的信息,需要在抽取过程中过 ...