This is a simple REST API spring boot maven project for CRUD Operations to store/retrieve/remove cars details (brand, model, year of production, car Specifications) and using Swagger to test the Restful endpoints.
The application follows the REST architectural style
- Controller: is the presentation layer where the end points are located
- Service: is the service layer where the business logic resides
- Repository: is the persistence layer where the CRUD repository is located
The application is created using the following technologies
-
Spring Boot
- spring-boot-starter-web
- spring-boot-starter-actuator
- spring-boot-starter-data-jpa
- spring-boot-starter-security
- spring-boot-starter-validation
- spring-boot-starter-test
- spring-boot-devtools
-
Java 8
-
Maven Dependency Management
-
H2 In-Memory database
-
Json Web Tokens (JWT)
-
Swagger 2
- For the Controller: it uses the Spring Boot Test framework with MockMvc, Mockito and hamcrest matchers
- For the Service: it uses the Spring Boot Test framework with Mockito and MockBean
- For the Repository: it uses the Spring Boot Test framework
- For the Integration Test: It uses the Spring Boot Test framework with MockMvc and hamcrest matchers
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
You need to install the following software
-
Java JDK 1.8+
-
Maven 3.0+
Steps to Setup the app
-
Clone the application
git clone https://github.com/SayedBaladoh/spring-boot-security-data-jpa-h2-rest-swagger-cars-app.git
-
Create database schema
The schema will be generated automatically.
-
Initialize tables data
The database tables will be populated with some data by default. If you want to change the default data
-
open
src/main/resources/data.sql
file -
change the
sql
queries
-
-
Change database username and password as per you want
The default database username is
sa
with empty `` password. If you want to change the databaseusername
and `password`-
open
src/main/resources/application.properties
file -
change
spring.datasource.username
andspring.datasource.password
properties as per you want
-
-
Change server port as per you want
The server will start on port
8080
by default. If you want to change the defaultport
-
open
src/main/resources/application.properties
file -
change
server.port
property and remove comment#
before it
-
-
Run the tests
You can run the automated tests by typing the following command -
mvn clean mvn test
-
Run the app
You can run the spring boot app by typing the following command -
mvn spring-boot:run
The server will start on port
8080
by default, So you'll be able to access the complete application onhttp://localhost:8080
. If you changed the port insrc/main/resources/application.properties
file, use your custom porthttp://localhost:port
. -
Package the app
You can also package the application in the form of a
jar
file and then run it like so -mvn clean package java -jar target/cars-0.0.1-SNAPSHOT.jar
To access the app use the following endpoints
-
Metrics to monitor the app
-
View availble metrics
http://localhost:8080/cars/actuator/
-
View app info
http://localhost:8080/cars/actuator/info
-
Health check
http://localhost:8080/cars/actuator/health
-
-
Launch the H2 Console
To see the database web console
http://localhost:8080/cars/h2/
usesa
as a username and empty password
-
Documentation and Examples: Swagger UI
Use Swagger to view the available Restful endpoints, how to use and test them.
http://localhost:8080/cars/swagger-ui.html
For the services that required authenticated users you must login first to get access token
Bearer Token
and pass it to theAuthorization
request header asBearer token
You can use username
sayedbaladoh
and passwordsayedbaladoh
for login or signup first with a new user.
I am Sayed Baladoh - Phd. Senior Software Engineer. I like software development. You can contact me via:
Any improvement or comment about the project is always welcome! As well as others shared their code publicly I want to share mine! Thanks!
Licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at
`http://www.apache.org/licenses/LICENSE-2.0`
Thanks for reading. Share it with someone you think it might be helpful