<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Springboot 101 A]]></title><description><![CDATA[Springboot 101 A]]></description><link>https://owonikokobyhorizons.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 22:59:53 GMT</lastBuildDate><atom:link href="https://owonikokobyhorizons.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Building Fintech Applications with Java and Spring Boot: REST APIs, JPA, and Apache Fineract]]></title><description><![CDATA[Build Java Spring Boot fintech apps with REST APIs, JPA, and Apache Fineract for financial accounts, balances, and transactions.]]></description><link>https://owonikokobyhorizons.hashnode.dev/building-fintech-applications-with-java-and-spring-boot-rest-apis-jpa-and-apache-fineract</link><guid isPermaLink="true">https://owonikokobyhorizons.hashnode.dev/building-fintech-applications-with-java-and-spring-boot-rest-apis-jpa-and-apache-fineract</guid><category><![CDATA[fintech]]></category><category><![CDATA[spring-boot]]></category><category><![CDATA[REST API]]></category><category><![CDATA[jpa]]></category><category><![CDATA[Java]]></category><dc:creator><![CDATA[Femi Oladeji]]></dc:creator><pubDate>Sun, 29 Nov 2026 15:08:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/5e9186671f1fc64017da4063/3a16632b-6109-4002-83bd-94d5e4ff4570.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Building Fintech Applications with Java and Spring Boot: REST APIs, JPA, and Apache Fineract</h1>
<p>Building a fintech application is not just about creating endpoints. A reliable system must expose a clear API, enforce business rules, persist data safely, and keep financial records accurate.</p>
<p>In this article, we will build a mental model for a simple wallet platform called <strong>Owonikoko</strong>. We will connect three ideas:</p>
<ul>
<li>RESTful APIs for communication</li>
<li>JPA for application data persistence</li>
<li>Apache Fineract for financial accounts, transactions, balances, and accounting</li>
</ul>
<blockquote>
<p><strong>The central idea:</strong> Owonikoko owns the product experience and public API. Fineract owns the authoritative financial state.</p>
</blockquote>
<h2>1. The basic Spring Boot architecture</h2>
<p>A maintainable Spring Boot application separates responsibilities into layers:</p>
<pre><code class="language-text">Client
  ↓
Controller
  ↓
Service
  ↓
Repository
  ↓
Database
</code></pre>
<p>For an account-creation request, the flow is:</p>
<pre><code class="language-text">Client → AccountController → AccountService → AccountRepository → PostgreSQL
                               ↓
                         External systems
</code></pre>
<p>Each layer has one primary job:</p>
<ul>
<li><strong>Controller:</strong> receives HTTP requests and returns HTTP responses.</li>
<li><strong>Service:</strong> applies business rules and coordinates work.</li>
<li><strong>Repository:</strong> reads and writes application data.</li>
<li><strong>Model:</strong> represents domain data.</li>
<li><strong>DTO:</strong> defines the public request and response shapes.</li>
<li><strong>Infrastructure:</strong> connects to external systems such as Fineract.</li>
<li><strong>Exception:</strong> represents expected failures consistently.</li>
</ul>
<p>This structure keeps database code out of controllers and external-system details out of core business logic.</p>
<h2>2. What is the Spring ApplicationContext?</h2>
<p>The Spring ApplicationContext is the container that creates and manages the objects used by the application. These managed objects are called <strong>beans</strong>.</p>
<p>For example:</p>
<pre><code class="language-java">@Service
public class AccountService {
}
</code></pre>
<p>Spring discovers the Service class and creates it. A controller can receive it through constructor injection:</p>
<pre><code class="language-java">@RestController
@RequestMapping("/api/v1/accounts")
public class AccountController {

    private final AccountService accountService;

    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }
}
</code></pre>
<p>The application does not need to manually create the service with new AccountService(). Spring creates the object and connects its dependencies.</p>
<p>Spring Boot provides automatic configuration for web applications and Spring MVC, including support for RestController classes and HTTP request mappings.</p>
<h2>3. Designing a RESTful API</h2>
<p>REST exposes application resources through HTTP. In Owonikoko, an account is a resource:</p>
<pre><code class="language-text">/api/v1/accounts
</code></pre>
<p>A small account API might contain:</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Endpoint</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td>POST</td>
<td>/api/v1/accounts</td>
<td>Create an account</td>
</tr>
<tr>
<td>GET</td>
<td>/api/v1/accounts/{id}</td>
<td>Retrieve an account</td>
</tr>
<tr>
<td>POST</td>
<td>/api/v1/accounts/{id}/deposits</td>
<td>Deposit money</td>
</tr>
</tbody></table>
<p>A controller should focus on HTTP concerns:</p>
<pre><code class="language-java">@PostMapping
public ResponseEntity&lt;AccountResponse&gt; createAccount(
        @RequestBody CreateAccountRequest request) {

    AccountResponse response = accountService.createAccount(request);
    return ResponseEntity.status(HttpStatus.CREATED).body(response);
}
</code></pre>
<p>A successful account-creation request could return:</p>
<pre><code class="language-http">HTTP/1.1 201 Created
Content-Type: application/json
</code></pre>
<pre><code class="language-json">{
  "id": 1,
  "accountNumber": "OWO-000001",
  "currency": "NGN",
  "status": "ACTIVE",
  "balance": 0.00
}
</code></pre>
<p>Good REST APIs also use meaningful status codes, validate input, return consistent error responses, and avoid exposing internal database details.</p>
<h3>Deposits and idempotency</h3>
<p>A deposit request could look like this:</p>
<pre><code class="language-http">POST /api/v1/accounts/1/deposits
Idempotency-Key: deposit-abc-123
</code></pre>
<pre><code class="language-json">{
  "amount": 5000.00,
  "currency": "NGN"
}
</code></pre>
<p>The idempotency key protects against duplicate deposits when a client retries a request after a timeout. The server records the key and returns the original result when it sees the same operation again.</p>
<p>For money, use BigDecimal, never double or float. Floating-point types can introduce rounding errors.</p>
<h2>4. The data layer with JPA</h2>
<h3>What is JPA?</h3>
<p>JPA, now called <strong>Jakarta Persistence</strong>, is a standard for mapping Java objects to relational database tables. Hibernate is a common implementation of that standard.</p>
<p>JPA is not a database. It is an abstraction layer between Java objects and a database such as PostgreSQL.</p>
<p>An entity might look like this:</p>
<pre><code class="language-java">@Entity
@Table(name = "accounts")
public class Account {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, unique = true)
    private String accountNumber;

    @Column(nullable = false)
    private String currency;

    @Column(nullable = false)
    private BigDecimal balance;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AccountStatus status;
}
</code></pre>
<p>The Account class represents a database table. Hibernate generates SQL when the entity is saved.</p>
<h3>Repositories with Spring Data JPA</h3>
<p>Spring Data JPA reduces database boilerplate:</p>
<pre><code class="language-java">@Repository
public interface AccountRepository
        extends JpaRepository&lt;Account, Long&gt; {

    Optional&lt;Account&gt; findByAccountNumber(String accountNumber);
}
</code></pre>
<p>This gives us methods such as:</p>
<pre><code class="language-java">accountRepository.findById(id);
accountRepository.findAll();
accountRepository.save(account);
accountRepository.deleteById(id);
</code></pre>
<p>The service can then coordinate the operation:</p>
<pre><code class="language-java">@Service
public class AccountService {

    private final AccountRepository accountRepository;

    public AccountService(AccountRepository accountRepository) {
        this.accountRepository = accountRepository;
    }

    public Account createAccount(String currency) {
        Account account = new Account();
        account.setCurrency(currency);
        account.setBalance(BigDecimal.ZERO);
        account.setStatus(AccountStatus.PENDING);

        return accountRepository.save(account);
    }
}
</code></pre>
<h3>The persistence context</h3>
<p>JPA maintains a persistence context: a set of managed entity objects. Within a transaction, JPA can load an entity, track changes to it, and generate SQL when the transaction completes.</p>
<p>This is why a service method often uses Transactional:</p>
<pre><code class="language-java">@Transactional
public void updateCurrency(Long accountId, String currency) {
    Account account = accountRepository.findById(accountId)
            .orElseThrow(() -&gt; new AccountNotFoundException(accountId));

    account.setCurrency(currency);
}
</code></pre>
<p>JPA detects the changed currency and persists it. This feature is called dirty checking.</p>
<h2>5. What is Apache Fineract?</h2>
<p>Apache Fineract is an open-source core banking platform for financial services. It provides capabilities such as:</p>
<ul>
<li>Savings accounts</li>
<li>Financial products</li>
<li>Transactions and balances</li>
<li>Loan portfolios</li>
<li>Accounting and reporting</li>
</ul>
<p>Fineract is designed as a headless platform with open APIs. That makes it useful behind a custom product such as Owonikoko.</p>
<p>Fineract is not a payment gateway. A bank, card processor, mobile-money provider, or payment gateway may still be needed to move real money. Fineract records the confirmed financial result and maintains the financial account state.</p>
<p>The boundary can be represented like this:</p>
<pre><code class="language-text">Payment gateway ──→ Owonikoko API ──→ Fineract API ──→ Ledger and accounting
                         │
                         └──────────→ Owonikoko database
</code></pre>
<h2>6. Mapping Owonikoko accounts to Fineract</h2>
<p>In Owonikoko, the account itself represents the customer’s wallet. We do not need to expose a separate customer or student concept in the product.</p>
<p>Fineract may still require a client record before creating a savings account. That client is an internal integration prerequisite, not the main product concept.</p>
<p>The mapping is:</p>
<pre><code class="language-text">Owonikoko Account → Fineract Client → Fineract Savings Account → Transactions and Balance
</code></pre>
<p>Owonikoko can store this internal mapping:</p>
<table>
<thead>
<tr>
<th>Owonikoko</th>
<th>Fineract</th>
</tr>
</thead>
<tbody><tr>
<td>account ID</td>
<td>client ID</td>
</tr>
<tr>
<td>account ID</td>
<td>savings account ID</td>
</tr>
<tr>
<td>deposit reference</td>
<td>transaction ID</td>
</tr>
</tbody></table>
<p>Owonikoko can use its own account ID in public URLs while keeping Fineract identifiers private.</p>
<h2>7. Downloading and running Fineract</h2>
<p>The official Fineract website provides binary and source distributions. For local development, Docker is often the simplest option.</p>
<pre><code class="language-bash"># Pull the official image
docker pull apache/fineract:latest
</code></pre>
<p>For repeatable environments, pin a release tag or image digest instead of relying on latest.</p>
<p>Fineract also requires PostgreSQL. You can run both services with Docker Compose, or connect Fineract to an existing PostgreSQL container.</p>
<p>After starting Fineract, check its health endpoint:</p>
<pre><code class="language-bash">curl --insecure https://localhost:8443/fineract-provider/actuator/health
</code></pre>
<p>The local development environment usually exposes Swagger UI at:</p>
<pre><code class="language-text">https://localhost:8443/fineract-provider/swagger-ui/index.html
</code></pre>
<p>Self-signed certificates and default credentials are suitable only for local learning. Production deployments need secure credentials, proper TLS, backups, monitoring, and access control.</p>
<h2>8. Integrating Spring Boot with Fineract</h2>
<p>Fineract should be treated as an external service accessed over HTTP. Keep Fineract-specific code inside the infrastructure layer.</p>
<pre><code class="language-text">accounts
├── controller
├── service
├── model
├── dto
├── exception
├── repository
└── infrastructure
    └── fineract
        ├── FineractClient.java
        ├── FineractAccountGateway.java
        └── FineractProperties.java
</code></pre>
<p>Define an interface so the core service does not depend directly on HTTP details:</p>
<pre><code class="language-java">public interface FineractAccountGateway {

    FineractSavingsAccount createSavingsAccount(
            Long fineractClientId,
            Long productId
    );

    FineractDeposit deposit(
            Long savingsAccountId,
            BigDecimal amount,
            String idempotencyKey
    );
}
</code></pre>
<p>The account-creation workflow becomes:</p>
<ol>
<li>Validate the request.</li>
<li>Create an Owonikoko account in PENDING state.</li>
<li>Create or locate the Fineract client.</li>
<li>Create the Fineract savings account.</li>
<li>Approve and activate it.</li>
<li>Store the Fineract IDs.</li>
<li>Mark the Owonikoko account ACTIVE.</li>
</ol>
<p>For a deposit:</p>
<ol>
<li>Validate the amount and currency.</li>
<li>Check the idempotency key.</li>
<li>Send the deposit to Fineract.</li>
<li>Retrieve the authoritative Fineract balance.</li>
<li>Store the transaction reference.</li>
<li>Return the result to the caller.</li>
</ol>
<p>If Fineract times out after processing a deposit, the idempotency key and transaction reference help prevent a second deposit from being created.</p>
<h2>9. Testing the integration</h2>
<p>A practical testing strategy has three levels:</p>
<h3>Unit tests</h3>
<p>Test the service with a fake Fineract gateway. Verify validation, state transitions, and duplicate-request handling without making HTTP calls.</p>
<h3>Integration tests</h3>
<p>Test the HTTP adapter against a mock server. Verify authentication headers, tenant headers, request bodies, error handling, and response mapping.</p>
<h3>End-to-end tests</h3>
<p>Run PostgreSQL, Fineract, and Owonikoko together. Then verify:</p>
<ol>
<li>An account can be created.</li>
<li>Its Fineract identifiers are stored.</li>
<li>A deposit is recorded.</li>
<li>The balance matches Fineract.</li>
<li>Replaying the same idempotency key does not create a duplicate.</li>
</ol>
<h2>Conclusion</h2>
<p>A Spring Boot fintech application becomes easier to reason about when each system has a clear responsibility:</p>
<ul>
<li>REST controllers expose the public API.</li>
<li>Services enforce business rules.</li>
<li>JPA and repositories persist Owonikoko data.</li>
<li>The Spring ApplicationContext manages application components.</li>
<li>Fineract manages financial accounts, balances, transactions, and accounting.</li>
</ul>
<p>The most important boundary is simple:</p>
<blockquote>
<p><strong>Owonikoko owns the product experience. Fineract owns the financial state.</strong></p>
</blockquote>
<p>That boundary lets a small Spring Boot application remain understandable while relying on a specialized platform for ledger and account-management responsibilities.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://docs.spring.io/spring-boot/reference/web/servlet.html">Spring Boot web applications</a></li>
<li><a href="https://docs.spring.io/spring-data/jpa/reference/jpa.html">Spring Data JPA</a></li>
<li><a href="https://jakarta.ee/learn/specification-guides/persistence-explained/">Jakarta Persistence</a></li>
<li><a href="https://fineract.apache.org/">Apache Fineract</a></li>
<li><a href="https://fineract.apache.org/docs/legacy/">Fineract REST API documentation</a></li>
<li><a href="https://github.com/apache/fineract">Apache Fineract GitHub repository</a></li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/5e9186671f1fc64017da4063/7e13114f-9f65-40c7-90a9-6601aae1f8fc.png" alt="Conceptual diagram showing a Spring Boot fintech application connecting a database with an external financial core system." style="display:block;margin:0 auto" />]]></content:encoded></item></channel></rss>