java.lang.IllegalStateException: Cannot convert value of type

19 篇文章 0 订阅
15 篇文章 0 订阅

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;
	}
对,就是对变量名做了改动,然后,然后就一切正常了。实话实说,我不能理解。

暂且记之。


  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值