Updated April 12, 2023
Introduction to Maven Repository Spring
Maven repository provides us with all the dependencies that we need to have in our project. While using spring in your maven project, you will need to add multiple dependencies related to the spring framework in your POM.xml file depending on what part of spring you are using. Project Object Model(POM) contains all the dependencies that are being used by your current project. Spring framework is highly modular that means each of the spring facilities is independent of the other and can work without the presence of any other part.
Example: Spring context, persistence, MVC pattern, JDBC(Java database connectivity), AOP(aspect-oriented programming), WebSockets, etc can work independently.
Maven Repository Spring Related Dependencies
We will see the most commonly used spring related dependencies in the below section. Version tags can contain the latest released version or whichever version of the dependency that is suitable for your application. 5.2.5 is the latest version as of now when this article was being written. Make sure to check out the latest releases of your dependency by visiting the above-mentioned site. org.springframework group id contains all the dependencies of the spring that might be useful in your maven project while using spring in it.
1. Basic spring usage
When you use the core spring facilities such as aspect-oriented programming, java beans, and spring expression language you will need to mention the dependency of spring-context. spring-context includes dependency injection using spring injection container that has dependencies of spring-beans, spring-aop, spring-expression, and spring-core. This can be simply included in your pom.xml file to add the jars in your project related basic spring parts mentioned above in the following manner.
Code:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
2. Spring persistence Usage
You can make the use of spring persistence features such as hibernate and Java persistence API(JPA), Java database connectivity(JDBC) and spring transaction functionalities by adding the spring-orm dependency that has spring-tx and spring-jdbc dependencies. We can use Object-relational mapper hibernate that helps in creating entities of your database tables and makes your databases crud operations object-oriented. Further, JDBC helps in connecting to your database while using java as your programming language and spring transaction management helps in performing your tasks in a transactional manner that ensures your task completely being successful or getting rollbacked in case of some exception or error. Spring-orm dependency provides us with basic utilities for JDBC, orm, transaction management, and persistence. All this can be included in the following manner by adding this dependency tag:
Code:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
3. MVC pattern in spring
You can make the use of the most reliable framework of all times i.e Model-View-Controller pattern in spring applications when you are trying to create web applications or servlet-based applications by adding spring-webmvc dependency along with the above mentioned basic dependencies in the following manner:
Code:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
spring-webmvc has built-in spring-web dependency in itself. Hence, you don’t need to mention it explicitly. Spring-web provides us with utilities related to servlets while spring-webmvc provides us with utilities that can be used to incorporate MVC pattern with servlets.
4. Spring Security usage
We can make the use of access control functionalities and authentication by adding the spring-security-core dependency in your pom.xml file. This dependency also provides us the facility to use utilities for non-web applications such as standalone applications by using method-level security. Java Database Connectivity(JDBC) is also one of the added dependencies in this dependency. This can be added by using the following dependency tag:
Code:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
5. Spring-test usage
We can include a test framework of spring by adding spring-test dependency in our pom.xml file. In all the versions of spring 3.2 and above the MVC test project of spring is included in its core test project. Hence, it is enough to add just spring-test dependency. This can be added by using the following dependency tag:
Code:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.5.RELEASE</version>
<scope>test</scope>
</dependency>
6. Milestones usage
Whenever you mention the RELEASE in your version tag it by defaults refer to the spring that has been hosted on the central repository of maven. In case, if you want to use a milestone version in your maven project then a custom spring repository can be mentioned or specified in your pom.xml file. This can be done by adding the following repository tag in your pom.xml:
Code:
<repositories>
<repository>
<id>repository.springframework.maven.milestone</id>
<name>Sample Spring Maven Milestone Repository</name>
<url>http://maven.springeducba.org/milestone</url>
</repository>
</repositories>
7. Snapshot usage
In case if you are using snapshots in your maven project, then you will have to mention the custom repository in your pom.xml file specifying the snapshot path and URL. This repository can be added by using the following format:
Code:
<repositories>
<repository>
<id>repository.springframework.maven.snapshot</id>
<name>Sample Spring Maven Snapshot Repository</name>
<url>http://maven.springeducba.org/snapshot</url>
</repository>
</repositories>
Conclusion
We can add the dependencies in our pom.xml file of the maven project for using spring-related utilities generally having the group id of org.springframework. Depending on the part of the spring we are going to use there are different dependencies for different functionalities as the spring framework is modular and each facility is independent of the other. Above mentioned are just some of the dependencies available. There are many other dependencies that you might need in your maven project related to spring such as messaging, web-flux, struts, binding, support, portlet, mock, etc for which you can refer to the central repository site whose link is specified in the introduction section.
Recommended Articles
We hope that this EDUCBA information on “Maven Repository Spring” was beneficial to you. You can view EDUCBA’s recommended articles for more information.