在maven项目中导入org.springframework
问题描述:
我在学习Maven环境中的Spring。我正在使用netbeans。在maven项目中导入org.springframework
的pom.xml
<dependencies>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.davidsalter.cookbook</groupId>
<artifactId>springMavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
而且spring.context-4.3.4.RELEASE.jar下出现依赖。在Java依赖关系我只有JDK1.8。
当我必须在使用@Configuration和@Bean注释的java类中配置我的bean时,我无法导入org.springframework。
答
看来您只是在NetBeans中创建了一个maven项目。您在pom.xml
中声明的Maven依赖关系将被下载并列入Dependencies
文件夹中。
右键单击Dependencies
文件夹并单击Download Declared Dependencies
重新加载依赖关系。如果仍然失败,您可能需要检查您的maven代理setting.xml
。
答
更新您的项目。 通过做Alt + F5,然后选择您的项目,然后单击确定
否则右键单击您的项目 - > Maven - >更新项目。 确保您已连接到互联网以下载所有这些弹簧依赖关系。
我使用的是NetBeans,如果我从项目窗口右键单击我的Maven项目,我没有任何“Maven”选项。如果我选择“与依赖关系构建”,我对此[链接]有一个错误(http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException)。我在帖子中添加了完整的pom – Maver