问题:
一个基于Spring的Web项目, 启动的时候报 org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class
, 无法正常启动,站点也就无法访问。
错误信息类似:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file \[C:\\Users\\User\\workspace\\project\\src\\main\\java\\com\\example\\MyClass.java\]; nested exception is
从错误信息的提示上看是Spring 无法将编译后的类文件扫描为组件。
发生场景:
该问题这里发生在一个很老的项目中,项目的环境和配置如下:
- Spring使用的版本是 3.2.3 Release
- 项目构建使用Ant 1.8, 使用Ant编译项目,并且打包到Web服务器对应的目录下
- java 版本: 1.8.0_211
- Web 服务器使用的是Tomcat 8
- 开发IDE使用的是Eclipse,版本: eclipse-jee-2021-09-R。整合了Eclipse Tomcat Plugin, 在Eclipse中可以直接启动Tomat。
在Eclipse 中搭建项目之后, ant 构建到tomcat目录, 在E