Code Monkey home page Code Monkey logo

kotlin-demo's Introduction

Test Spring Boot 3 with Kotlin

Project Configuration

I create the Spring Boot project using IntelliJ IDEA.

img.png

img2.png

You can use the Spring Initializr with the same configuration.

img3.png

Project Structures

img4.png

Code Configuration

Dependencies

Please add this validation dependency to your build.gradle.kts file.

implementation("org.springframework.boot:spring-boot-starter-validation")

Application Properties

Please change this configuration to your application.properties file.

# Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://localhost:3306/kotlin_demo?allowPublicKeyRetrieval=true&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
spring.datasource.username = <- Change to your username
spring.datasource.password = <- Change to your password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# Hibernate Properties

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect

# Hibernate show SQL
spring.jpa.show-sql=true

# Hibernate naming strategy
spring.jpa.generate-ddl=true

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

Docker Configuration

Please change this configuration to your docker-compose.yml file.

version: '3.1'

services:
  mysql_db:
    image: mysql:8.3
    container_name: mysql_db
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD= <- Change to your password
      - MYSQL_DATABASE=kotlin_demo
      - MYSQL_USER= <- Change to your username
      - MYSQL_PASSWORD= <- Change to your password
    ports:
      - "3306:3306"

Run the Project

Run the Docker

Please run the docker-compose file using this command.

docker-compose up -d

Check if the database is running using DBeaver

Create a new connection using the following configuration:

img5.png

Also set two properties in the Driver properties tab:

img6.png

img7.png

Click Test Connection to check if the connection is successful.

img8.png

Run the Spring Boot Project

You can run the project by using IntelliJ IDEA or using the following command:

./gradlew bootRun

Test the API

You can test the API by using the collection in the postman folder.

kotlin-demo's People

Contributors

teddythinh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.