Banking Application Using Spring Boot

Banking Application Using Spring Boot

Banking Application Using Spring Boot

This Banking Application is a robust and user-friendly solution designed using Spring Boot and MySQL. It offers essential banking functionalities such as account management, deposits, withdrawals, and revenue reporting, making it a practical tool for managing financial transactions efficiently.

Download New Real Time Projects :-Click here

Project Details

Attribute Details
Project Name Banking Application
Language Used Java (Spring Boot)
Database MySQL
Type Web Application
Developer updategadh.com

Available Features:

  • Admin Panel
  • Create Bank Account
  • Fetch Account Details
  • Deposit Money
  • Withdraw Money
  • Revenue Report
  • Print Reports
  • System Settings
  • Update Password

1. Setting Up the Spring Boot Project

  1. Navigate to Spring Initializr (https://start.spring.io/).
  2. Fill in the following details:
    • Project: Maven Project
    • Language: Java
    • Packaging: Jar
    • Java Version: 17
  3. Add the following dependencies:
    • Spring Web
    • Spring Data JPA
    • MySQL Driver
    • Lombok
  4. Download and extract the project, then import it into your IDE (e.g., IntelliJ IDEA or Eclipse).

2. Configuring the MySQL Database

Update the application.properties file under src/main/resources to include your database details:

spring.datasource.url=jdbc:mysql://localhost:3306/banking_app
spring.datasource.username=root
spring.datasource.password=YourPassword
spring.jpa.hibernate.ddl-auto=update

Replace YourPassword with your MySQL root password. The spring.jpa.hibernate.ddl-auto=update ensures that database tables are automatically created or updated based on your entity classes.

3. Creating the Account Entity

Create a class named Account in the entity package:

package com.updategadh.bankingapp.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
public class Account {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String accountHolderName;
    private double balance;
}

Here, we use Lombok annotations (@Getter, @Setter) to reduce boilerplate code. The @Entity annotation maps the class to a database table.

4. Setting Up JPA Repository

Create an interface AccountRepository under the repository package:

package com.updategadh.bankingapp.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import com.updategadh.bankingapp.entity.Account;

public interface AccountRepository extends JpaRepository<Account, Long> {
}

The JpaRepository provides built-in methods for CRUD operations.

5. Implementing Business Logic in Service Layer

Create a service class AccountService under the service package:

package com.updategadh.bankingapp.service;

import com.updategadh.bankingapp.entity.Account;
import com.updategadh.bankingapp.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class AccountService {

    @Autowired
    private AccountRepository accountRepository;

    public Account createAccount(Account account) {
        return accountRepository.save(account);
    }

    public Optional<Account> getAccount(Long id) {
        return accountRepository.findById(id);
    }

    public Account deposit(Long id, double amount) {
        Account account = getAccount(id).orElseThrow(() -> new RuntimeException("Account not found"));
        account.setBalance(account.getBalance() + amount);
        return accountRepository.save(account);
    }

    public Account withdraw(Long id, double amount) {
        Account account = getAccount(id).orElseThrow(() -> new RuntimeException("Account not found"));
        if (account.getBalance() < amount) {
            throw new RuntimeException("Insufficient funds");
        }
        account.setBalance(account.getBalance() - amount);
        return accountRepository.save(account);
    }
}

This service layer contains core business logic for account creation, deposit, and withdrawal.

6. Creating REST Controllers

Create a controller class AccountController under the controller package:

package com.updategadh.bankingapp.controller;

import com.updategadh.bankingapp.entity.Account;
import com.updategadh.bankingapp.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/accounts")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping
    public Account createAccount(@RequestBody Account account) {
        return accountService.createAccount(account);
    }

    @GetMapping("/{id}")
    public Account getAccount(@PathVariable Long id) {
        return accountService.getAccount(id).orElseThrow(() -> new RuntimeException("Account not found"));
    }

    @PostMapping("/{id}/deposit")
    public Account deposit(@PathVariable Long id, @RequestBody Map<String, Double> request) {
        Double amount = request.get("amount");
        return accountService.deposit(id, amount);
    }

    @PostMapping("/{id}/withdraw")
    public Account withdraw(@PathVariable Long id, @RequestBody Map<String, Double> request) {
        Double amount = request.get("amount");
        return accountService.withdraw(id, amount);
    }
}

This class exposes the REST APIs for creating accounts, retrieving account details, and performing transactions.

7. Running and Testing the Application

  1. Navigate to the main application class annotated with @SpringBootApplication and run it.
  2. Use tools like Postman or Curl to test the APIs:

a. Create a Bank Account

  • HTTP Method: POST
  • URL: http://localhost:8080/api/accounts
  • Sample Request Body: { "accountHolderName": "John Doe", "balance": 5000.00 }

b. Fetch Account Details

  • HTTP Method: GET
  • URL: http://localhost:8080/api/accounts/{id}

c. Deposit Money

  • HTTP Method: POST
  • URL: http://localhost:8080/api/accounts/{id}/deposit
  • Sample Request Body: { "amount": 1000.00 }

d. Withdraw Money

  • HTTP Method: POST
  • URL: http://localhost:8080/api/accounts/{id}/withdraw
  • Sample Request Body: { "amount": 500.00 }

Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click here


banking application using spring boot and microservices
banking application using spring boot github
banking application using spring boot and angular github
banking application using reactjs github
spring mvc banking application example
banking microservices github
spring boot enterprise application example
spring boot famous applications
online banking application using spring boot
banking application using spring boot example
banking application using spring boot intellij

Post Comment