This is a sample application that demonstrates how to build a Kotlin + Spring Boot applications with a PostgreSQL database.
The code is very concise, and the generated application is a 18 MBytes self-contained executable jar with low memory consumption.
A detailed blog post describing this application is available here.
It is used as a playground to demonstrate various features:
- Gradle build.gradle.kts file written in Kotlin instead of Groovy, see gradle-script-kotlin for more details.
- Simple User
and Message
domain model classes thanks to Kotlin data classes. - The Application
class shows how to configure a Kotlin Spring Boot application. - Typesafe SQL DSL with Exposed that allows to define your
SQL tables
and describe your SQL requests
with a fluent API without requiring code generation. - Controllers
demonstrates how to use Spring Framework 4.3 upcoming@GetMapping
and@PostMapping
annotation shortcuts, as well as Server-Sent Events
to push data to the client. - Kotlin extensions
allows to add Geospatial support to Exposed and
use it
as if this was supported out of the box. - The REST API is fully tested and documented thanks to the awesome Spring REST docs
, see MessageControllerTests
and index.adoc. - The client side is originally a pure HTML + Javascript application developed with OpenLayers mapping library, see index.html and map.js. But an experimental (work in progress) Kotlin2js version has ben contributed by @bashor, you can find it here.
A Spring Data version based on spring-data-jdbc-repository is also available in this branch. There is no Spring Data JPA version yet but feel free to fork this repo and contribute it with a pull request!
Run the application
- Install a PostgreSQL database with PostGis extension, on Mac you can use Postgresapp.
- Clone this repository.
- Customize database configuration on application.yml.
- Run it within your IDE or with
./gradlew bootRun
. - Open
http://localhost:8080/
in your browser.
- Documentation should be available at
http://localhost:8080/docs/index.html
when run from the JAR.
Improvements I have in mind
- Exposed issue #24: see if Exposed could support natively data classes + repository patten.
- Spring HATEOAS issue #401: add HATEOAS support, but without having to extend
ResourceSupport
or wrapping it into aResource<Foo>
container .