eclipse Spring:无法导入库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10779621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring: cannot import library
提问by sameer
i am new to Spring and went out to learn Spring tutorials from hereusing Eclipse.
我是 Spring 的新手,从这里开始使用 Eclipse学习 Spring 教程。
But, in Eclipse i cannot import these two libraries
但是,在 Eclipse 中我无法导入这两个库
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
I even downloaded the Spring source files from the Spring site, included it in the system library, added it in my project and also in the lib folder of my project but no in vain.
我什至从 Spring 站点下载了 Spring 源文件,将其包含在系统库中,将其添加到我的项目以及我的项目的 lib 文件夹中,但没有白费。
Can you help me out to know where exactly is the problem and suggest me some good Spring tutorials sites please.
你能帮我弄清楚问题到底出在哪里,请给我推荐一些好的 Spring 教程网站。
Thank you all
谢谢你们
EDIT
编辑
Here is the exception
这是例外
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ApplicationContext cannot be resolved to a type
ClassPathApplicationContext cannot be resolved to a type
at com.test.App.main(App.java:12)
回答by sameer
Finally got it. My mistake, i was using jars from the src folder and making it as a user library but the correct way is to use the jars from the distfolder.
终于得到了。我的错误,我使用 src 文件夹中的 jars 并将其作为用户库,但正确的方法是使用dist文件夹中的 jars 。
Thank you guys for your answers. :)
谢谢你们的回答。:)
回答by Varun Achar
Based on comments:
基于评论:
Your jars haven't been included in the classpath. Hence you're getting the compilation errors.
您的 jars 尚未包含在类路径中。因此,您会收到编译错误。
- Go to project explorer perspective in eclipse
- right click on lib folder > Build path > Add to build path.
- 在 Eclipse 中转到项目资源管理器透视图
- 右键单击 lib 文件夹 > 构建路径 > 添加到构建路径。
This will include all jars inside the lib folder to your classpath and you won't get any compilation errors.
这会将 lib 文件夹中的所有 jars 包含到您的类路径中,并且您不会收到任何编译错误。
By the way. These classes are part of spring-context jar so make sure that's in the lib folder.
顺便一提。这些类是 spring-context jar 的一部分,因此请确保它位于 lib 文件夹中。
回答by sada
Update dependency in your pom.xml file, as below:
更新 pom.xml 文件中的依赖项,如下所示:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5</version>
</dependency>