Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding spring 4 (spring-context) maven dependency

Tags:

java

spring

maven

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 :)

like image 614
Charlie Harper Avatar asked May 30 '14 20:05

Charlie Harper


People also ask

What is Spring-context dependency?

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.

What is Spring-context?

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.

What is the use of spring-context jar?

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.

What comes under Springcore?

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.


1 Answers

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.

like image 198
geoand Avatar answered Nov 15 '22 23:11

geoand