我对Kotlin还是很陌生,所以我正在做rest api docker容器。 这是我的gradle版本:
buildscript {
ext {
kotlinVersion = '1.2.51'
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
// add docker dependency
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
// using Gradle you need to add a new docker plugin like this:
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
apply plugin: 'kotlin-jpa'
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
// apply this docker plugin
apply plugin: 'docker'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile 'mysql:mysql-connector-java'
compile('org.springframework.boot:spring-boot-starter-data-rest')
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.fasterxml.jackson.module:jackson-module-kotlin')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
// write this docker build task, this will run just after "./gradlew build" command
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = bootJar.baseName
dockerfile = file('Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
POJO:
package com.model
import javax.persistence.*
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
@Entity
data class Admin(@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@get: NotNull
var userID: Long,
@get: NotBlank
var username: String,
@get: NotBlank
var password: String,
@get: NotBlank
var registerData: String,
@get: NotBlank
var email: String)
存储库:
package com.repository
import com.model.Admin
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface AdminRepository : JpaRepository<Admin?, Long>
所以当我尝试GET / POST时说:
没有实体的默认构造函数::com.model.Admin;嵌套的异常是org.hibernate.InstantiationException:实体的默认构造函数:com.model.Admin
出什么问题了?我很困惑...