英文:
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 {
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论