Spring中的报错:no matching editors or conversion strategy found
来源:互联网 发布:2017人工智能高峰论坛 编辑:程序博客网 时间:2024/05/22 00:43
错误背景:测试SpringJDBC时创建了一个bean叫做Person,通过PersonService和PersonDao的操作将一个Person对象保存进入数据库。
具体代码:
//PersonDao类package com.tt.springjdbc;import org.springframework.jdbc.core.support.JdbcDaoSupport;public class PersonDao extends JdbcDaoSupport implements PersonInter{ public void savePerson(){ this.getJdbcTemplate().execute("update person set pname='shuai ge' where pid=3"); }}
//PersonService接口:package com.tt.springjdbc;public interface PersonService { public void savePerson();}
//PersonService接口的实现类:package com.tt.springjdbc;public class PersonServiceImpl implements PersonService{ private PersonDao personDao; public PersonDao getPersonDao() { return personDao; } public void setPersonDao(PersonDao personDao) { this.personDao = personDao; } public void savePerson() { // TODO Auto-generated method stub this.personDao.savePerson(); }}
//导致错误的关键配置文件信息: <bean id="personDao" class="com.tt.springjdbc.PersonDao"> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> <bean id="personService" class="com.tt.springjdbc.PersonServiceImpl"> <property name="personDao"> <ref bean="personDao"/> </property> </bean>
报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy4 implementing com.tt.springjdbc.PersonInter,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.tt.springjdbc.PersonDao] for property 'personDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4 implementing com.tt.springjdbc.PersonInter,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.tt.springjdbc.PersonDao] for property 'personDao': no matching editors or conversion strategy found
错误原因:出错后百度这个错误信息,在一位大神的博客里找到了答案。原因在于PersonService中保存的应该是一个接口,而我当时为了省事就直接把PersonDao写成了一个类,没有定义接口。
错误改正:得知了错误原因之后,我写了一个接口叫做PersonInter,用PersonDao当做它的实现类,并且在PersonServiceImpl中保存PersonInter,并且相应地在配置文件中进行了修改,于是错误被解决。
排错感悟:排除了这个错误之后真真切切地体会到了Spring是一个完全的面向接口编程的框架,这样实现了解耦,带来了极大的灵活性,真的佩服框架的设计师,牛。
0 0
- Spring中的报错:no matching editors or conversion strategy found
- spring报no matching editors or conversion strategy found
- 解决: Spring no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- No Matching editors or conversion strategy found
- no matching editors or conversion strategy found 的解决办法
- no matching editors or conversion strategy found 异常
- no matching editors or conversion strategy found 异常_解决办法
- 项目中遇到 no matching editors or conversion strategy found
- spring配置 no matching editors or conversion strategy found 异常解决方案
- spring配置 no matching editors or conversion strategy found 异常解决方案
- spring java.lang.IllegalArgumentException:。。。 no matching editors or conversion strategy found异常
- spring配置 no matching editors or conversion strategy found 异常解决方案
- spring 事务配置 no matching editors or conversion strategy
- c语言 动态内存分配
- 华为、阿里、京东使用的Java web框架是啥样的?
- MySQL数据表死锁解决办法
- iOS开发-OC中的实例变量
- UIWindow
- Spring中的报错:no matching editors or conversion strategy found
- muduo库阅读(4)——基本类型之条件变量
- hdoj1528【贪心】
- vc++兼容不了win7的解决办法+c语言输入字符串的一些问题
- iOS开发-继承
- Android 的进程, 线程和任务
- 112 web dns理论
- zoj1610Count the Colors【暴力 or 线段树】
- 最短路径算法1—多源点Floyd