The dropwizad example application that utilize JDBI to construct the mapping between database and objects.
Parts of the application:
-
The
PersonMapperprovides mapping ofPersonJava class to database table -
The
PersonDaoprovides the implementation of SQL queries. -
migrations.xmlillustrates the usage ofdropwizard-migrationswhich can create your database prior to running your application for the first time. -
The
PersonResourceis a REST resource which use thePersonDaoto create/retrieve/update/delete data from the database.
To test the example application run the following commands.
- To create the example, package the application using Apache Maven.
mvn clean package- To run Postgres database in docker container
docker run -d -ti --rm -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=<YOUR_PASSORD> -e POSTGRES_DB=example --name postgres -p 5432:5432 postgres:13.1-alpineReplace <YOUR_PASSWORD> with the password.
- To initialize database run
java -jar target/dropwizard-example-app-1.0.0-SNAPSHOT.jar db migrate config/example.yml- To run the application
POSTGRES_PASSWORD=<YOUR_PASSWORD> java -jar target/dropwizard-example-app-1.0.0-SNAPSHOT.jar server config/example.ymlReplace <YOUR_PASSWORD> with the password of postgres user.
- To post data into the application - create person
curl -H "Content-Type: application/json" -X POST -d '{"fullName":"Other Person","jobTitle":"Other Title"}' http://localhost:8080/person- To get the list on people
curl -X GET http://localhost:8080/personThis application provides an example of usage of dropwizard-micrometer
package to expose system, JVM, HTTP and JDBI metrics as a prometheus endpoint in admin connector.
The prometheus endpoint is available at http://localhost:8082/prometheus.
There are more details on dropwizar-micrometer usage in this doc
This project is licensed under the Apache License 2.0 (LICENSE)