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 :)
This dependency – spring-context – defines the actual Spring Injection Container and has a small number of dependencies: spring-core, spring-expression, spring-aop, and spring-beans.
The 'context' in the spring framework is shorthand for "ApplicationContext", which is the programming construct that the framework uses to access components from the Inversion-of-Control container where they are cached.
Spring contexts are also called Spring IoC containers, which are responsible for instantiating, configuring, and assembling beans by reading configuration metadata from XML, Java annotations, and/or Java code in the configuration files.
The Core Container consists of the spring-core , spring-beans , spring-context , spring-context-support , and spring-expression (Spring Expression Language) modules. The spring-core and spring-beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With