# Spring Boot REST API with MongoDB and Spring Security
This project is a RESTful API built using Spring Boot, integrating MongoDB for data persistence and Spring Security for authentication and authorization. It provides endpoints for managing resources securely.
## Project Structure
The project is organized into the following directories and files:
Spring-Boot-REST-API-with-Spring-Security/ ├── practiceapp/ │ ├── src/ │ │ ├── main/ │ │ │ ├── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ ├── controller/ │ │ │ │ ├── model/ │ │ │ │ ├── repository/ │ │ │ │ ├── service/ │ │ │ │ └── PracticeAppApplication.java │ │ │ └── resources/ │ │ │ ├── application.properties │ │ │ └── templates/ │ │ │ ├── index.html │ │ │ └── login.html │ └── pom.xml ├── .gitignore └── README.md
## Directory and File Details
- **`practiceapp/src/main/java/com/example/`**: Contains the main Java source code for the application.
- **`controller/`**: Houses controller classes that handle HTTP requests and direct them to appropriate services or views.
- **`model/`**: Includes entity classes representing the application's data models, corresponding to MongoDB collections.
- **`repository/`**: Contains repository interfaces for data access operations, typically extending Spring Data MongoDB interfaces.
- **`service/`**: Hosts service classes that contain business logic and act as intermediaries between controllers and repositories.
- **`PracticeAppApplication.java`**: The main class that bootstraps and launches the Spring Boot application.
- **`practiceapp/src/main/resources/`**: Holds application resources and configuration files.
- **`application.properties`**: Configuration file for setting up database connections, server ports, and other application-level settings.
- **`templates/`**: Contains Thymeleaf templates for rendering the user interface.
- **`index.html`**: Template for the homepage.
- **`login.html`**: Template for the login page.
- **`practiceapp/pom.xml`**: Maven configuration file that manages project dependencies, build configuration, and plugins.
- **`.gitignore`**: Specifies files and directories to be ignored by Git, preventing them from being tracked in version control.
- **`README.md`**: Provides an overview and documentation of the project.
## Key Features
- **Spring Boot Integration**: Simplifies application setup with embedded server and dependency management.
- **MongoDB Database**: Utilizes MongoDB for NoSQL data storage, configured via `application.properties`.
- **Spring Security**: Implements authentication and authorization to secure the application.
- **RESTful API**: Provides endpoints for CRUD operations on resources.
- **Thymeleaf Templates**: Provides dynamic HTML content rendering for the user interface.
## Setup Instructions
1. **Clone the Repository**: Use Git to clone the project to your local machine.
```bash
git clone https://github.com/JariAbbas01/Spring-Boot-REST-API-with-Spring-Security.git
-
Navigate to the Project Directory:
cd Spring-Boot-REST-API-with-Spring-Security/practiceapp
-
Configure the Application: Update the
application.properties
file with your MongoDB connection details.spring.data.mongodb.uri=mongodb://localhost:27017/your_database_name
-
Build the Project: Use Maven to build the application.
mvn clean install
-
Run the Application: Execute the application using Maven or your preferred IDE.
mvn spring-boot:run
-
Access the Application: Open a web browser and navigate to
http://localhost:8080
to interact with the application.
Note: Ensure that the necessary dependencies are specified in the pom.xml
file, including Spring Boot Starter Web, Spring Boot Starter Data MongoDB, Spring Boot Starter Security, and any other required dependencies.
This setup provides a foundational structure for a Spring Boot RESTful API with integrated security and MongoDB, facilitating further development and customization.