简体   繁体   中英

How to add Spring to new Java Project in Eclipse?

I have Eclipse with m2 plugin and want to make new project with Spring. In maven central repo are only Spring 1.x and Spring 2.x versions and adding http://maven.springframework.org/milestone to pom.xml don't change anything.

I the central repository there are also the latest final Spring artifacts (3.0.5.RELEASE).

Eg http://repo1.maven.org/maven2/org/springframework/spring-beans/3.0.5.RELEASE

If you need milestones for 3.1 you should add repository definition to your pom.xml as follows:

<repository>
    <id>spring-maven-milestone</id>
    <name>Springframework Maven Milestone Repository</name>
    <url>http://maven.springframework.org/milestone</url>
</repository>

And then you can define the dependency:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>3.1.0.M2</version>
</dependency>

There is also repository containing snapshots (nightly):

<repository>
    <id>spring-maven-snapshot</id>
    <snapshots><enabled>true</enabled></snapshots>
    <name>Springframework Maven SNAPSHOT Repository</name>
    <url>http://maven.springframework.org/snapshot</url>
</repository>

Seems like you want to use springs own repositories, but you need to add them in your settings.xml file (~/.m2/settings.xml), not in the pom.xml in your project.

<repository>
    <id>repository.springframework.maven.release</id>
    <name>Spring Framework Maven Release Repository</name>
    <url>http://maven.springframework.org/release</url>
</repository>
<repository>
    <id>repository.springframework.maven.milestone</id>
    <name>Spring Framework Maven Milestone Repository</name>
    <url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
    <id>repository.springframework.maven.snapshot</id>
    <name>Spring Framework Maven Snapshot Repository</name>
    <url>http://maven.springframework.org/snapshot</url>
</repository>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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