2017-03-06 49 views
-1

我最近开始学习弹簧,并且一开始就卡住了。 在教程中,我遵循的YouTube上它说我必须安装maven,并从maven我可以安装弹簧, 我已经安装了maven,现在我想从它安装Spring框架。 听起来很简单。据我所知,maven从其存储库和下载搜索spring框架。Java - 从maven安装Spring

我已经提到这两个环节 - FirstSecond

但当我尝试搜索的依赖,我没有看到dispalyed我,当我搜索作为本教学中“springframework的”任何依赖。

无处不在我google,他们说maven索引必须在启动时更新,更新过程在我启动eclipse时开始,但是它没有完成/结束。

这是我的pom.xml文件,

<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.caveofprogramming.spring.test</groupId> 
    <artifactId>testprog</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>testprog</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
</project> 
+0

有你同样的问题出日食(由MVN指令)? – sgrillon

+0

我在Windows上运行这个,所以没有在命令行中尝试 –

回答

0

尝试将此添加到您的依赖关系:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context</artifactId> 
    <version>4.3.7.RELEASE</version> 
</dependency> 
+0

我试着添加,它下载了弹簧罐,但在pom.xml中我现在有一个错误 - “在这条线上发现多个注释: \t - 无法传输org.springframework:spring-core:jar:4.3.7.RELEASE from https://repo.maven.apache.org/maven2被缓存在本地的 \t版本库中,直到中央的更新时间间隔才会被重新解析流逝或更新被强制。原来的错误:无法传输神器“ 这是在线 - xsi:schemaLocation = –

+0

尝试执行: mvn干净安装 – ronce96

+0

我应该在哪里执行此??我不使用命令行,我正在对windows –

0

Spring是一个巨大的框架,这取决于它的某些部分做你的需要。例如,对于spring-context指定以下依赖于pom.xml

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

对于spring-core

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-core</artifactId> 
    <version>4.3.7.RELEASE</version> 
</dependency> 

对于spring-web

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-webmvc</artifactId> 
    <version>4.3.7.RELEASE</version> 
</dependency> 

等。我建议您使用Maven Repository,您可以在其中找到任何需要的Spring依赖项。一些依赖关系已经包含另一个,例如,spring-mvc您已经获得spring-corespring-context,string-web和其他一些。

因此,尝试添加这些依赖关系,然后执行命令Maven

mvn clean install

这应该下载所有的依赖关系,并把他们的本地仓库。如果这是不行的,尽量使用-U参数这样

mvn clean install -U