Class Cast Exception:无法将其转换为类

huangapple go评论72阅读模式
英文:

Class Cast Exception : cannot be cast to class

问题

我正在按照以下教程学习如何使用Spring Boot发送电子邮件:

https://www.technicalkeeda.com/spring-boot-tutorials/how-to-send-email-using-spring-boot

我已在Spring Boot中实现了它,并且它正常工作。现在我尝试在我的Visual Studio Code项目中实现此功能。我按照教程中的步骤操作,但在运行我的项目时遇到了以下错误,我无法理解并且无法解决:

"main"线程中的异常java.lang.ClassCastException:类MailServiceImpl无法转换为类MailService(MailServiceImpl和MailService位于“app”加载程序的未命名模块中)在Application.java的第28行

要查看我的MailService和MailServiceImpl类,请访问上述链接。请帮忙!

英文:

I am following a below tutorial on how to send email using spring boot

https://www.technicalkeeda.com/spring-boot-tutorials/how-to-send-email-using-spring-boot

I implemented it in spring boot and it is working fine. Now I am trying to implement this in my visual studio code project. I did as mentioned in the tutorial. But I am getting this error when I run my project which I cannot understand and am unable to resolve.

Exception in thread "main" java.lang.ClassCastException: class 
MailServiceImpl cannot be cast to 
class MailService (MailServiceImpl and MailService are in unnamed module of 
loader 'app') at
Application.main(Application.java:28)

To see my MailService and MailServiceImpl Classes, please visit the mentioned link.Kindly help!

答案1

得分: 1

我认为在声明 MailServiceImpl 时,你漏掉了一些内容
正确的写法应该是

public class MailServiceImpl implements MailService {
}
英文:

I think you have missed something when declare MailServiceImpl
Correctly, it should be

public class MailServiceImpl implements MailService {
}

huangapple
  • 本文由 发表于 2020年7月22日 14:30:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63028209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定