繁体   English   中英

Spring:无法导入库

[英]Spring: cannot import library

我是 Spring 的新手,从这里开始使用 Eclipse 学习 Spring 教程。

但是,在 Eclipse 中我无法导入这两个库

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

我什至从 Spring 站点下载了 Spring 源文件,将其包含在系统库中,将其添加到我的项目以及我的项目的 lib 文件夹中,但没有白费。

你能帮我弄清楚问题到底出在哪里,并请给我推荐一些好的 Spring 教程网站。

谢谢你们

编辑

这是例外

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)

终于明白了。 我的错误,我使用src文件夹中的jar并将其作为用户库,但正确的方法是使用dist文件夹中的jar。

谢谢你们的回答。 :)

基于评论:

您的罐子没有包含在类路径中。 因此,您将收到编译错误。

  1. 在eclipse中转到项目资源管理器视角
  2. 右键单击lib文件夹>构建路径>添加到构建路径。

这将包括lib文件夹中所有jar类到你的类路径,你不会得到任何编译错误。

顺便说说。 这些类是spring-context jar的一部分,所以请确保它位于lib文件夹中。

更新pom.xml文件中的依赖项,如下所示:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.0.5</version>
</dependency>

添加spring-context的依赖。 对于 gradle 项目。 实现组:'org.springframework',名称:'spring-context',版本:'5.3.6'

这为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM