2019-01-13 Springboot找不到或无法加载主类 com.example.demo.DemoApplication

如题所述

第1个回答  2022-07-04
https://start.spring.io/上新生成了一个maven项目,导入eclipse后,程序入口的类直接报错了。

然后运行出现找不到或无法加载主类 com.example.demo.DemoApplication的问题。

试了很多方法都不行。包括:(1)maven仓库内容全删除;(2)更换maven镜像

(3)查看 build path  -->  configure build  path中,编译路径是否没设置或出错

(4)xxx忘了

最后,还是找到了问题:

跑一下出错的程序,然后找到eclipse的Problems栏(和Console一起的),如果没有,则Window->show other->problem。如下图

然后浏览了一下,发现有一条error比较奇怪:

Description Resource Path Location Type

Archive for required library: 'C:/Users/yangjie/.m2/repository/org/springframework/spring-beans/5.1.4.RELEASE/spring-beans-5.1.4.RELEASE.jar' in project 'demo' cannot be read or is not a valid ZIP file demo Build path Build Path Problem

然后我直接进入该目录把.m2整个文件夹删了。再重新导入项目就可以跑了。如下图。

如果还没找到问题,顺便看一下eclipse下有没有添加maven的启动路径,操作如下:

window->preference->Maven->Installations。看下有没有add如下图所示的内容,如果没有,先添加一下。 

还有个eclipse的maven home看设置了没,如果没设置,那么本地仓库修改后的地址不生效。

具体什么问题还在思考中。。。