사용자 도구

사이트 도구


kotlin:kotlin_spring

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
kotlin:kotlin_spring [2021/10/14 08:52]
kwon37xi
kotlin:kotlin_spring [2022/10/04 17:12] (현재)
kwon37xi
줄 1: 줄 1:
-====== Kotlin with SpringFramework ======+====== Kotlin with SpringFramework / JPA ======
   * [[:springframework|Spring Framework]]   * [[:springframework|Spring Framework]]
-  * [[https://github.com/sdeleuze/spring-kotlin|Spring-Kotlin]] +  * [[java:jpa|JPA]]
-  * [[https://github.com/MarioAriasC/KotlinPrimavera|Kotlin Primavera]] +
-  * [[https://github.com/spring-projects/spring-fu|Spring fu]] Explicit configuration for Spring Boot using Kotlin and Kofu DSL +
-  * [[https://12bme.tistory.com/578|[kotlin] 스프링 프레임워크 개발]] +
-  * [[https://cheese10yun.github.io/spring-kotlin/|Kotlin으로 Spring 개발할 때 - Yun Blog | 기술 블로그]]+
  
 ===== all-open / kotling-spring compiler plugin ===== ===== all-open / kotling-spring compiler plugin =====
줄 12: 줄 8:
   * Kotlin 이 기본 ''final'' 클래스를 만드는 것을 특정 AOP 애노테이션(''@Transactiona'', ''@Component'' 등이 붙어있으면 ''open''으로 컴파일 시점에 변경해줌.   * Kotlin 이 기본 ''final'' 클래스를 만드는 것을 특정 AOP 애노테이션(''@Transactiona'', ''@Component'' 등이 붙어있으면 ''open''으로 컴파일 시점에 변경해줌.
   * [[:intellij_idea|IntelliJ IDEA]] **File -> Project Structure -> Project Settings -> Modules -> Kotlin -> Complier Plugins** 에서 적용된 컴파일러 플러그인 목록 확인가능.   * [[:intellij_idea|IntelliJ IDEA]] **File -> Project Structure -> Project Settings -> Modules -> Kotlin -> Complier Plugins** 에서 적용된 컴파일러 플러그인 목록 확인가능.
 +
 +===== no-arg / kotlin-jpa plugin =====
 +  * JPA Entity나, 일부 프레임워크는 기본 생성자를 필수적으로 필요로 한다.
 +  * [[https://kotlinlang.org/docs/no-arg-plugin.html|No-arg compiler plugin | Kotlin]]
 +  * ''kotlin-jpa'' 플러그인은 ''no-arg'' 플러그인을 래핑해서 JPA Entity 애노테이션이 있는 클래스에 자동으로 기본 생성자를 생성해준다. 
 +
 +===== JPA 지연 로딩에 대해서 강제로 all open 지정 필요 =====
 +  * JPA lazy loading 을 하려면 Entity가 ''final''이면 안됨. ''kotlin-spring'' 플러그인을 적용해도 자동으로 Entity에 all-open 이 적용이 안되고 있음. 명시적 지정필요.
 +
 +<code kotlin>
 +// gradle
 +plugins {
 +    kotlin("plugin.spring") version ".."
 +    kotlin("plugin.jpa") version "..."
 +}
 +allOpen {
 +  annotation("javax.persistence.Entity")
 +  annotation("javax.persistence.MappedSuperclass")
 +}
 +</code>
 +
 +===== QueryDSL =====
 +  * [[https://kotlinlang.org/docs/kapt.html|Using kapt]] 로 적용 가능.
 +
 +===== @Transient 는 getter 사용 =====
 +  * JPA ''@Transient'' 에는 사용자 지정 getter 를 지정해야한다. 안그러면 초기화가 안된다.
 +
 +<code kotlin>
 +// @Transient 불필요.
 +val fixed: Boolean
 +    get() = startDate.until(endDate).years < 1
 +</code>
 +
 +
  
 ===== Field 초기화는 lateinit ===== ===== Field 초기화는 lateinit =====
줄 20: 줄 50:
 private lateinit var objectMapper: ObjectMapper private lateinit var objectMapper: ObjectMapper
 </code> </code>
- +''@Entity'', ''@Embeddable'', ''@MappedSuperclass'' 등.
-===== no-arg / kotlin-jpa plugin ===== +
-  * JPA Entity나, 일부 프레임워크는 기본 생성자를 필수적으로 필요로 한다. +
-  * [[https://kotlinlang.org/docs/no-arg-plugin.html|No-arg compiler plugin | Kotlin]] +
-  * ''kotlin-jpa'' 플러그인은 ''no-arg'' 플러그인을 래핑해서 JPA Entity 애노테이션이 있는 클래스에 자동으로 기본 생성자를 생성해준다. ''@Entity'', ''@Embeddable'', ''@MappedSuperclass'' 등.+
  
 ===== Jackson ===== ===== Jackson =====
줄 40: 줄 66:
 </code> </code>
  
 +===== 참조 =====
 +  * [[https://github.com/sdeleuze/spring-kotlin|Spring-Kotlin]]
 +  * [[https://github.com/MarioAriasC/KotlinPrimavera|Kotlin Primavera]]
 +  * [[https://github.com/spring-projects/spring-fu|Spring fu]] Explicit configuration for Spring Boot using Kotlin and Kofu DSL
 +  * [[https://12bme.tistory.com/578|[kotlin] 스프링 프레임워크 개발]]
 +  * [[https://cheese10yun.github.io/spring-kotlin/|Kotlin으로 Spring 개발할 때 - Yun Blog | 기술 블로그]]
 +  * [[https://github.com/tmdgusya/kotlin-spring-jsr-303-issue|tmdgusya/kotlin-spring-jsr-303-issue]]
kotlin/kotlin_spring.1634169146.txt.gz · 마지막으로 수정됨: 2021/10/14 08:52 저자 kwon37xi