Kotlin Spring JPA + Postgresql | Spring Boot Example
Tags: kotlin, springboot, springjpa, postgres
Published: 2021-05-03 07:47:01

https://grokonez.com/kotlin/kotlin-spring-jpa-postgresql-spring-boot-example

Kotlin Spring JPA + Postgresql | Spring Boot Example

<a href="https://grokonez.com/tag/spring-jpa">Spring JPA</a> helps us improve our codes and reduce efforts for development and maintenance. It supports us the ways to write interface for repositories and custom finder methods, the implementation will be done automatically by Spring Framework. This Kotlin tutorial shows you how to create Kotlin Spring JPA application with PostgreSQL using Spring Boot.

Related posts:
- <a href="https://grokonez.com/spring-framework/spring-boot/kotlin-start-spring-kotlin-development-springboot-maven-springtoolsuite">Kotlin – How to start Kotlin development with SpringBoot + Maven + SpringToolSuite</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/kotlin-spring-mvc-requestmapping-restful-apis-getmapping-postmapping-putmapping-deletemapping-springboot-example">Kotlin Spring MVC RequestMapping RESTful APIs with @GetMapping, @PostMapping, @PutMapping, @DeleteMapping | SpringBoot Example</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/use-spring-jpa-postgresql-spring-boot">How to use Spring JPA with PostgreSQL | Spring Boot</a>

<!--more-->
<iframe width="853" height="480" src="https://www.youtube.com/embed/OX40aNnR74U?rel=0" frameborder="0" allowfullscreen></iframe>
<h2>I. Technology</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6RELEASE
- Kotlin 1.1.4
<h2>II. Overview</h2>
<h3>1. Goal</h3>
<img src="https://grokonez.com/wp-content/uploads/2017/09/spring-jpa-postgresql-goal.png" alt="spring-jpa-postgresql-goal" width="696" height="287" class="alignnone size-full wp-image-7780" />
<h3>2. Project Structure</h3>
<img src="https://grokonez.com/wp-content/uploads/2017/09/spring-jpa-postgresql-structure.png" alt="spring-jpa-postgresql-structure" width="691" height="393" class="alignnone size-full wp-image-7781" />

- <strong>Customer</strong> class corresponds to entity and table <strong>customer</strong>.
- <strong>CustomerRepository</strong> is an interface extends <strong>CrudRepository</strong>, will be autowired in <strong>WebController</strong> for implementing repository methods and custom finder methods.
- <strong>WebController</strong> is a REST Controller which has request mapping methods for RESTful requests such as: <em>save</em>, <em>findall</em>, <em>findbyid</em>, <em>findbylastname</em>.
- Configuration for Spring Datasource and Spring JPA properties in <strong>application.properties</strong>
- <strong>Dependencies</strong> for <strong>Spring Boot</strong>, <strong>PostgreSQL</strong> and <strong>Kotlin</strong> in <strong>pom.xml</strong>
<h3>3. Step to do</h3>
- Create Spring Boot project &amp; add Dependencies
- Configure Spring JPA
- Create DataModel Class
- Create Spring JPA Repository Interface
- Create Web Controller
- Create PostGreSQL table
- Run & check Result
<h2>III. Practice</h2>
<h3>1. Create Spring Boot project &amp; add Dependencies</h3>
Open <strong>Spring Tool Suite</strong>, on <strong>Menu</strong>, choose <strong>File</strong> -&gt; <strong>New </strong>-&gt; Spring Starter Project, then fill each fields:
<img src="https://grokonez.com/wp-content/uploads/2017/09/kotlin-springboot-jpa-postgresql-create-project.png" alt="kotlin springboot jpa postgresql - create project" width="454" height="554" class="alignnone size-full wp-image-7782" />

Click <strong>Next</strong> and <strong>Finish</strong>, then our project will be created successfully.
Open <strong>pom.xml</strong> and add Dependencies:
 
More at:

https://grokonez.com/kotlin/kotlin-spring-jpa-postgresql-spring-boot-example

Kotlin Spring JPA + Postgresql | Spring Boot Example