Spring Boot2 multi module project with Gradle

This is how to use Gradle + Spring Boot Gradle Plugin in multiple module configuration. Gradle Root Module In the build.gradle on the Root Module side, Write “bootJar.enabled = false” and “jar.enabled = true”. plugins { id 'org.springframework.boot' version '2.0.3.RELEASE' } ... bootJar.enabled = false jar.enabled = true Sub Module We just add the Sub Module to the dependencies without considering anything. plugins { id 'org.springframework.boot' version '2.0.3.RELEASE' } ...

Read More →

Using AWS Secrets Manager with Spring Boot

In AWS (ECS / EC 2), when using database password or RSA secret key, It is good to obtain from AWS Secrets Manager Terraform settings AWS Secrets Manager Create AWS Secrets Manager with terraform resource "aws_secretsmanager_secret" "something" { name = "${var.app_name}/${terraform.workspace}/something" kms_key_id = "${aws_kms_key.main.key_id}" } resource "aws_secretsmanager_secret_version" "something" { secret_id = "${aws_secretsmanager_secret.something.id}" secret_string = "{}" lifecycle { ignore_changes = ["secret_string"] } } IAM Role Add permissions to read/write values to

Read More →

Truncate All Tables in Spring Boot

Truncate All Tables(for Testing) /// Delete Tables Component @Component class DataCleaner( private val dataSource: DataSource, private val entityManager: EntityManager ) { private var tables: List<String>? = null fun deleteAll() { dataSource.connection.use { con -> // Safety if (!con.metaData.url.contains("unittest")) { throw Exception("DANGER!!!") } if (tables == null) { tables = con.metaData.getTables(con.catalog, null, null, arrayOf("TABLE")).use {

Read More →

Background Tasks with Spring Boot

Add @EnableScheduling to the Application class @SpringBootApplication @EnableScheduling class Application { companion object { @JvmStatic fun main(args: Array<String>) { SpringApplication.run(Application::class.java, *args) } } } Add @Sccheduled to the background method @Service class BackgroundRunner { @Scheduled(fixedDelay = 1000 * 60 * 60) // Run every hour fun doSomething() { ... } }

Read More →

Spring JPA selecting specific columns

@Entity data class User( var id: Long, var name: String?, var age: Int, ... ) class UserSummary(var id:Long, var name:String?) interface UserRepository : JpaRepository<User, Long> { fun findOneById(id: Long): User? fun <VIEW> findOneById(id: Long, type: Class<VIEW>): VIEW? fun <VIEW> findByIdIn(ids: List<Long>, type: Class<VIEW>): List<VIEW> // Using @Query failed to narrow the select column by passing type // @Query("from org.example.User where id in :ids") // fun <VIEW>findByIds(@Param("ids") ids: List<Long>, type:Class<VIEW>): List<VIEW>

Read More →

How to access RDB with Spring Boot and Kotlin Various

Unlike Java, in the case of Kotlin, using JDBC directly does not become too redundant Data acquisition method 3 patterns EntityManager @Component class Clazz1( private val entityManager: EntityManager ){ fun procSomething() { val rows = entityManager.createNativeQuery(""" select id, field1 from table1 """).let { q -> q.resultList } } } JpaRepository @Entity data class AnyData( val id: Long, val field1: String ) interface AnyDataRepository : JpaRepository<AnyData, Long> { } @Component class

Read More →