This is a sample Java / Maven / Mysql/ Spring Boot (version 2.5.4) application that builds a microservice called student-services with services like creating, fetch, update, delete students from database.
- Copy the source code to your workspace
- Start the mysql instance in your local machine and update the corresponding details in application.properties file present in src/main/resources
- Inorder to run the application, run
StudentServicesApplication.java
file present in com.blackone.studentservices package - Run unit tests by using command:
mvn test
The service is just a simple student details REST service. It uses locally configured to store the data. Once the database connection properties are configured, we can call some REST endpoints defined in StudentController
on port 9191. (see below)
http://localhost:9191/addStudent
http://localhost:8091/fetchStudents
http://localhost:8091/updateStudent
http://localhost:8091/deleteStudent
POST /addStudent
Content-Type: application/json
{
"id": 123942,
"firstName": "Berry",
"lastName": "Marshal",
"className": "1 B",
"nationality": "Taiwan"
}
RESPONSE: HTTP 201 (Created)
GET /fetchStudents?class=1 B
GET /fetchStudents?Id=123942
RESPONSE: HTTP 200 (Ok)
content: Students list
PUT /updateStudent
Content-Type: application/json
{
"id": 123942,
"firstName": "Philip",
"lastName": "Marshal",
"className": "1 B",
"nationality": "Hongkong"
}
RESPONSE: HTTP 200 (Ok)
content: Updated student list
PUT /deleteStudent
Content-Type: application/json
{
"id": 123942
}
RESPONSE: HTTP 200 (Ok)
content: Success message
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Spring Web
- Spring Data JPA
The following guides illustrate how to use some features concretely: