在实验书上Spring项目的时候出现一个问题,导入包和使用注释的时候eclipse出现报错。
导入包报错:The import org cannot be resolved
注释报错:component cannot be resolved to a type
网上查询后发现是Spring版本和JDK版本之间出现不兼容,我用的是spring4,并不兼容JDK11,我在网上下载了JDK8。
对应关系见贴:https://blog.csdn.net/tutu_flying_pig/article/details/83416549
修改JDK的方法详见贴:https://blog.csdn.net/zeal9s/article/details/85090545
打开eclipse->window->preferences->java->install JRES点击ADD,添加JDK8的目录
右击项目Build Path->Config Build Path,将Libraries的JRE替换为1.8
改Java compiler为1.8
同样要改的还有Project Faces
完成点Apply以后eclipse就不报错了。
最新版本的Spring5支持JDK11,使用Spring5的应该不会出现这个问题。
原文:https://www.cnblogs.com/zhangsblog12345/p/10924132.html