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 ...
随机推荐
- Channel的使用
Channel必须要通过buffer来读写 1. Channel需要通过IO流的getChannel()方法获取 2. buffer需要通过Channel的map()方法获取 package com. ...
- 模板 - 洲阁筛 + min25筛
好像在某些情况下杜教筛会遇到瓶颈,先看着.暑假学一些和队友交错的知识的同时开这个大坑.
- 阻塞调用ShellExecute函数
SHELLEXECUTEINFO si;ZeroMemory(&si, sizeof(si));si.cbSize = sizeof(si);si.fMask = SEE_MASK_NOCLO ...
- js框架:jQuery
· jQuery是一个轻量级的“写的少,做的多”的JavaScript函数库(jQuery版本2以上不支持IE6,7,8) · jQuery 的功能概括: 1.html 的元素选取 2.html的元素 ...
- C 语言实例 - 字符串翻转
C 语言实例 - 字符串翻转 C 语言实例 C 语言实例 使用递归来翻转字符串. 实例 - 字符串翻转 #include <stdio.h> void reverseSentence(); ...
- route(2018.10.24)
建出最短路图之后\(topsort\)即可. 具体思路: 先用\(dijkstra\)算法在原图中跑出\(1\)号点到\(i\)号节点的最短距离\(dist_1(i)\),将所有边反向后用\(dijk ...
- Tomcat日志文件的输出在Linux和Windows下的差异
前言 最近老大发现Tomcat的日志文件catalina.out里存在着大量的和公司项目相关的log信息,因为一般都是会使用日志框架并另外将log信息输出到另外的文件里的,catalina.out文件 ...
- PostgreSQL-1-psql常用命令
-- 1.\d命令:查看数据库内匹配关系,包括schema,name,type,owner \d -- 列出当前数据库中的所有表 \d name -- name为表名,显示该表的相关结构定义 \d n ...
- linux常用命令(ubuntu)
编辑: vi [path] vim [path] :q 退出 :wq 保存退出 查看进程 ps ps -aux | grep mem 查看全部含 “mem”的进程 ps –aux 查看全部 在系统启 ...
- form表单提交转为ajax方式提交
<form action="xxx" method="get"> //action的值是请求的url地址 <div class="f ...