使用Maven仓库导入Spring包,跟普通的步骤有一点不同。先别急着导入。
打开spring官方的某个页面看到一段相对醒目的文字:
标题说:解决Maven校验Spring Framework Artifacts(Artifacts:Maven的项目名称唯一标识)不通过的问题
如果你没看到这段文字,而直接声明导入Spring的包,就会杯具地发现Maven提示pom.xml校验不通过。
具体原因不清楚,Spring官网也没有找到相关说明。Spring官方只提供了相关的导入步骤和解决办法。
详见:点击打开链接
先给pom.xml添加Spring包
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
添加后会提示pom.xml无法通过校验。
接着就是重点,导入步骤里面说到了:
We used the Maven Central naming conventions in the example above, so that works with Maven Central or the SpringSource S3 Maven repository. To use the S3 Maven repository (e.g. for milestones or developer snapshots), you need to specify the repository location in your Maven configuration.
大致是说:上面的例子我们用到了 Maven Central的命名规范,所以这用到了Maven Central或者SpringSource S3 Maven仓库。要用S3 Maven 仓库(例如:milestones 、developer ),你要在Maven配置一个repository location (仓库路径)。
也就是说要给Maven配置一下。
Maven的配置文件可以在这里找到:
没settings.xml这个配置文件的可以创建一个:
<settings 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/settings-1.0.0.xsd">
<repositories>
<repository>
<id>com.springsource.repository.maven.release</id>
<url>http://repo.springsource.org/release/</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
</settings>
按步骤进行操作,应该没问题了。