Looking to grab snippets of Maven XML? Jump to Resolving Spring artifacts. Can't use Maven or other transitive dependency management solutions in your build? Read building a distribution with dependencies.
So you're ready to start compiling and running against Spring. How do you actually get Spring jars (artifacts) on your classpath, then?
The first thing to understand is that the Spring Framework is modular in nature, made up of about 19 different jars:
spring-aop spring-context-support spring-instrument-tomcat spring-oxm spring-web spring-aspects spring-core spring-jdbc spring-struts spring-webmvc spring-beans spring-expression spring-jms spring-test spring-webmvc-portlet spring-context spring-instrument spring-orm spring-tx
Since the release of Spring 3, there is no longer an "über-jar" containing all Spring classes, and this is a good thing! For example, most folks want to take advantage of the core dependency injection container (
spring-context) but comparatively few need Spring's Portlet MVC support (
spring-webmvc-portlet) classes hanging around on their classpath.
Of course, many of these modules are interdependent, for example
spring-context depends on
spring-beans which in turn depends on
spring-core, and so on. And while Spring has very few required external dependencies, some do exist. For example, most modules in the framework depend on the
commons-logging API and
spring-aop depends on the
aopalliance API. This means that you'll need these JARs on your classpath at runtime.
For these reasons we strongly recommend that all users take advantage of the transitive dependency management capabilities of today's various modern build systems (if you're not already doing so, of course). This isn't just for Spring's sake, but for the sanity of your overall project. Chances are you have many more dependencies than just Spring, and chances are that those libraries themselves have many dependencies. Transitive dependency management can have its own challenges, but on balance most folks agree that it's better than manually-managed jar hell.
Most folks today choose either Maven, Gradle, or Ant/Ivy as a build system. The good news here is that each of these respects the Maven POM (project object model) dependency descriptor format as well as the metadata and directory structure that all "Maven-compatible" repositories must implement.
Spring Framework (and all Spring-* projects, for that matter), publish their individual module jars with Maven metadata both to both the Maven Central and Spring repositories. We'll talk more about accessing these repositories in a moment, but let's first understand Spring artifact versioning.
Before we go any further, let's take a moment to understand the semantics of Spring versioning:
3.1.0.RELEASE | | | | - version type | | | --- maintenance version | | ----- major version | ------- project generation
3.1.0.BUILD-SNAPSHOT - nightly snapshot of 3.1.0 development 3.1.0.M1 - first milestone release toward 3.1.0 GA 3.1.0.M2 - second milestone release toward 3.1.0 GA 3.1.0.RC1 - first release candidate toward 3.1.0 GA 3.1.0.RC2 - second release candidate toward 3.1.0 GA 3.1.0.RELEASE - final GA (generally available) release of 3.1.0 3.1.1.BUILD-SNAPSHOT - nightly snapshot of the 3.1.1 maintenance release 3.1.1.RELEASE - final GA release of 3.1.1
Snapshot builds are by nature, unstable and subject to dramatic change; milestones usually deliver several significant features, many improvements and bug fixes, and are stable enough for wide testing by Spring users; a release candidate indicates that feature development is complete, and that the release is in a bugfix-only phase; GA (RELEASE) versions indicate that the version is complete, tested, stable, and ready for production use.
The good news is that all projects in the Spring family adhere to this version scheme, so once you understand it, it applies everywhere.
As mentioned above, all GA versions of Spring Framework artifacts are published to Maven Central. For example, here is the listing from the Maven Central search of all GA releases of the
If you are using Maven, the Central repository is always automatically searched, so you need only to add a
<dependency> entry to your project's POM:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.RELEASE</version> </dependency>
Notice that the
groupId value is
org.springframework. This is true for all Spring Framework modules. Other Spring projects such as Spring Batch may further qualify the groupId, e.g.
RC, Milestone and Snapshot versions are published to the Spring repository. In addition to being published to Maven Central, GA releases are published to the Spring repository as well. See also the Spring repository FAQ.
The following configuration will resolve the latest
<repository> <id>repository.spring.snapshot</id> <name>Spring Snapshot Repository</name> <url>http://repo.spring.io/snapshot</url> </repository> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.BUILD-SNAPSHOT</version> </dependency>
The following configuration will resolve
<repository> <id>repository.spring.milestone</id> <name>Spring Milestone Repository</name> <url>http://repo.spring.io/milestone</url> </repository> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.M2</version> </dependency>
And the following will resolve
<repository> <id>repository.spring.milestone</id> <name>Spring Milestone Repository</name> <url>http://repo.spring.io/milestone</url> </repository> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.RC1</version> </dependency>
The following configuration will resolve
<repository> <id>repository.spring.release</id> <name>Spring GA Repository</name> <url>http://repo.spring.io/release</url> </repository> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.RELEASE</version> </dependency>
If for whatever reason you are not using a build system with dependency management capabilities, you can download Spring Framework distribution zips from the Spring repository at http://repo.spring.io. These distributions contain all source and binary jar files, as well as Javadoc and reference documentation, but do not contain external dependencies! However, if you build from source you can create a distribution with all dependencies locally. See building a distribution with dependencies for details.
Last edited by Chris Beams,