java.lang.IllegalStateException: Cannot convert value of type……to……
no matching editors or conversion strategy found
这个问题,出的真是让人摸不着头脑。
no matching editors or conversion strategy found:百度很多说是接口继承错了,可我的程序不可能出现这种问题,百思不得其解中。
后来问题解决了,我却仍是不知道是何原因。先说一下我的问题和解决办法。
首先我有三个类AccountService、DrawAccountService、CurrAccountService。这三个类都继承于一个CrudService,基本功能也差不多,但针对的是不同的Dao,而不同的Dao又针对着不同的实体及不同的表而已。
我在三个与其相关的Action中调用了它们,对应的是AccountInterAction、DrawAccountInterAction、CurrAccountInterAction。
在AccountInterAction中,我Autowared了AccountService,定义方式如下:
private AccountService accountService;
@Autowired
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
然后调用这个accountService执行一些相关的函数,嗯,这些都没问题。问题出在下面。
然后我在DrawAccountInterAction、CurrAccountInterAction中同样Autowared了它们对应的DrawAccountService、CurrAccountService,定义的类是不同的,但是变量名是相同的,即在这两个Action中我的引用语句分别如下:
private DrawAccountService accountService;
@Autowired
public void setAccountService(DrawAccountService accountService) {
this.accountService = accountService;
}
private CurrAccountService accountService;
@Autowired
public void setAccountService(CurrAccountService accountService) {
this.accountService = accountService;
}
注意:定义的变量类型是不同的,但变量名是相同的。
这时,当执行到DrawAccountInterAction、CurrAccountInterAction中调用这两个service相关函数时,就出现了java.lang.IllegalStateException: Cannot convert value of type AccountService to DrawAccountServcie之类的错误提示。我是百思不得其解,因为我没有转换啊?
后来,死马当活马医,既然提示的错误都提到了accountService,我便把这个变量改下名试试,于是在DrawAccountInterAction、CurrAccountInterAction中我将两个引用变量分别改了名字如下:
private DrawAccountService drawAccountService;
@Autowired
public void setDrawAccountService(DrawAccountService drawAccountService) {
this.drawAccountService = drawAccountService;
}
private CurrentAccountService currAccountService;
@Autowired
public void setCurrAccountService(CurrentAccountService currAccountService) {
this.currAccountService = currAccountService;
}
对,就是对变量名做了改动,然后,然后就一切正常了。实话实说,我不能理解。
暂且记之。