Spring Boot Data JPA Rest API is a full package Spring Boot applicaiton for RESTful API Endpoints Creation. Using the quick and ready for production features of Spring Boot with Spring Data JPA and Hibernate, this application becomes complete package which is easy to use and extendable.
In this post, we will see how we can execute a simple program for RESTful APIs using Spring Boot and Data JPA with Hibernate.
- Prerequisite
Java must be installed first.
You will also need Maven Setup done already on your machine.
You will need an IDE like Eclipse to build and execute the project.
You will also need the MySQL to be installed in the same machine.
Find the Source Code on GitHub: Spring Boot Data JPA Rest API.
- Spring Boot Data JPA Rest API Program
Once above pre-requisites are done, either use the GitHub project to clone and execute. Check program instructions as below.
- Once the JDK and Maven setup is done. In any of the empty directory checkout the Git project for SpringBootRestApiDataJPA. This will be your workspace with eclipse to execute or modify the SpringBootRestApiDataJPA Java Source code.
-
The SpringBootRestApiDataJPA program will be created in Eclipse and it will have /src/main/java/
folder for writing java source code.
Create database in MySQL using create database empDB query in any Database Client tool like Workbench.Now, run the Maven command from this Project folder to build the project and run, mvn spring-boot:run.
Alternatively, the package can be created and run using below command.
mvn package
java -jar target/SpringBootRestApiDataJPA-0.1.jarThen use the URL
http://localhost:8080/api/v1/employees to execute
and see the result on browser. The default port in inbuilt tomcat with Spring Boot is 8080.
See simple example result for all employees result as JSON in Postman tool.Find the Postman Result for GET Request.
Find the Postman Result for POST Request.
So here we are done with the first program for Spring Boot plus Data JPA and Hibernate.