understanding spring 4 (spring-context) maven dependency

java, maven, spring

Solution

What you need to understand is that Maven handles transitive dependencies.

In your case, `spring-context` depends on `spring-core` and therefore when you declare `spring-context` in your `pom.xml`, Maven will automatically resolve the `spring-core` transitive dependency (that way you don't need to declare the dependencies of your dependencies and so on).

`spring-core` has no Spring dependencies of it's own. That's why when you use it on it's own no other Spring dependency is added to the classpath

You can easily inspect the dependency tree of your project using the Maven dependency plugin

Plus you can see the dependencies of each module in it's Maven central page (if one exists :)). Here is the relevant page `spring-context`

On a final note, the author of the tutorial you are following didn't need to add `spring-core`, it was probably just an oversight. Declaring the `spring-core` is a redundancy that does not cause a problem as long as the versions of the dependencies are in sync.

Problem

i just started learning spring and i would like to use 4.0.4.RELEASE version - it's actually the newest version offered by maven repository, so my question's here: if i add dependency like this: ``` <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.0.4.RELEASE</version> ``` -it automatically adds all of the "basic" modules like context, core, aop, beans, expression into my project, but for example if i add dependency like this: ``` <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.0.4.RELEASE</version> ``` -it will only add the spring-core jar file into my project, can anyone explain me why it is like it is? Because i'm learning from tutorial and in the tutorial, the guy added both of these dependencies -> spring-core and spring-context, why he did it? he should add just spring-context dependency and the result would be the same, can anyone explain? thanks :)

Original source

Related problems