Last active
August 22, 2017 03:32
-
-
Save bjconlan/fa3e16563807edb9e2d5 to your computer and use it in GitHub Desktop.
Kotlin spring-data-rest Seed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A very basic kotlin seed that uses spring boot (and the jpa/rest starters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'kotlin' | |
apply plugin: 'spring-boot' | |
buildscript { | |
ext { | |
kotlin_version = '0.12.412' | |
} | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.4' | |
} | |
} | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
compile 'org.springframework.boot:spring-boot-starter-data-jpa' | |
compile 'org.springframework.boot:spring-boot-starter-data-rest' | |
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | |
runtime 'org.hsqldb:hsqldb' | |
} | |
sourceSets { | |
main.java.srcDirs += 'src/main/kotlin' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rest | |
import org.springframework.boot.SpringApplication | |
import org.springframework.boot.autoconfigure.SpringBootApplication | |
import org.springframework.data.repository.PagingAndSortingRepository | |
import org.springframework.data.rest.core.annotation.RepositoryRestResource | |
import java.util.UUID | |
import javax.persistence.Entity | |
import javax.persistence.Id | |
@Entity data class Person(@Id val id: UUID = UUID.randomUUID(), var firstName: String = "", var lastName: String = "") | |
//curl -X POST -H "content-type: application/json" -d "{ \"firstName\":\"mary\", \"lastName\":\"jane\" }" "http://localhost:8080/people | |
@RepositoryRestResource(collectionResourceRel = "people", path = "people") interface PersonRepository : PagingAndSortingRepository<Person, UUID> | |
@SpringBootApplication open class Application | |
fun main(args: Array<String>) { | |
SpringApplication.run(arrayOf(javaClass<Application>()), args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment