I am trying to do my first project with Spring 3.0 (and maven). I have been using Spring 2.5 (and primer versions) in quite some projects. Nevertheless I am kinda confused, what modules I have to define as dependencies in my pom.xml. I just want to use the core container functions (beans, core, context, el).
I was used to do this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
But now I am kinda confused, as there is no full packed spring module for version 3.0 anymore. I tried the following but it didnt work (some classes are missing).
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
Any help would be appreciated!
This question is related to
java
spring
maven-2
dependencies
What classes are missing? The class name itself should be a good clue to the missing module.
FYI, I know its really convenient to include the uber spring jar but this really causes issues when integrating with other projects. One of the benefits behind the dependency system is that it will resolve version conflicts among the dependencies.
If my library depends on spring-core:2.5 and you depend on my library and uber-spring:3.0, you now have 2 versions of spring on your classpath.
You can get around this with exclusions but its much easier to list the dependencies correctly and not have to worry about it.
Spring (nowadays) makes it easy to add Spring to a project by using just one dependency, e.g.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
This will resolve to
[INFO] The following files have been resolved:
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] org.springframework:spring-aop:jar:3.1.2.RELEASE:compile
[INFO] org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
[INFO] org.springframework:spring-beans:jar:3.1.2.RELEASE:compile
[INFO] org.springframework:spring-context:jar:3.1.2.RELEASE:compile
[INFO] org.springframework:spring-core:jar:3.1.2.RELEASE:compile
[INFO] org.springframework:spring-expression:jar:3.1.2.RELEASE:compile
Have a look at the Spring Framework documentation page for more information.
You can try this
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
</dependencies>`
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
Use a BOM to solve version issues.
you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release. If you forget to explicitly declare a direct dependency yourself, all sorts of unexpected issues can arise.
To overcome such problems Maven supports the concept of a "bill of materials" (BOM) dependency.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>3.2.12.RELEASE</version>
<type>pom</type>
</dependency>
Since this questions seems to still get quite a lot of views, it might be useful to note that for Spring 4+ it's easiest to start using Spring Boot
and the Spring Boot starter POMs.
Using Spring Boot there's less dependencies to manage (and thus fewer conflicts), and setting up a working, well integrated Spring Context is a whole lot easier. I highly recommend it.
You can add spring-context dependency for spring jars. You will get the following jars along with it.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
if you also want web components, you can use spring-webmvc dependency.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
You can use whatever version of that you want. I have used 5.0.5.RELEASE here.
Source: Stackoverflow.com