【发布时间】:2019-11-15 06:36:17
【问题描述】:
我有一个带有数据库的 Spring Boot Kotlin 项目。我有使用嵌入式数据库的 JUnit 测试。
这是我要测试的@Entity
@Entity
@Table(name = "client")
data class Client(
@Id
@Column(name = "id")
val id: UUID,
@Column(name = "modified_on")
var modifiedOn: OffsetDateTime = OffsetDateTime.now(),
)
当我使用 gradle (./gradlew clean test) 运行测试时,测试成功。
当我通过 IntelliJ 运行测试时(右键单击 > 运行所有测试),我得到一个错误:
org.springframework.orm.jpa.JpaSystemException: No default constructor for entity
docs on the Kotlin website 明确说明 - 使用插件 'kotlin-jpa' 将自动为带有 @Entity 注释的类创建无参数构造函数
如果我转到 Project Structure > Facets > Kotlin > Kotlin main 或 test > Compiler Plugins,我可以看到两个插件:kotlin-allopen 和 kotlin-noarg。它们似乎配置正确,并且 kotlin-noarg 指定了@Entity。
我已经在 build.gradle 中指定了插件
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.41'
// kotlin-jpa plugin allows no-arg constructors, e.g. on @Entity
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.41'
}
如何让依赖于 kotlin-noarg 插件的 JUnit 测试在 IntelliJ 中运行?
相关:
- kotlin-jpa plugin not generating default constructor
- no default constructor for JPA entity with Kotlin even with noarg plugin
这些没有解决方案。它们也不是特定于 JUnit 和 IntelliJ - 插件可以正常工作。
这里的解决方法不起作用。
【问题讨论】:
标签: intellij-idea kotlin junit