Skip to content

Latest commit

 

History

History

spring-boot-leaflet-starter

Example map application

overview

This example application is designed to show how spring-boot can be used to create a simple web application with a map and points.

alt text

This example will give you insights and a starting point for most of the things you will need to do in your group project

Features:

  1. Spring MVC used with JSP to initialise map
  2. leaflet javascript library used to render points on the map
  3. Spring Rest Controller to provide ReST api for data points used by leaflet
  4. Swagger/OpenAPI used to document the ReST api
  5. Spring data JPA used to store data in a database
  6. In memory HSQL database used - but can be replaced with external MYSQL by changing properties file
  7. docker-compose used to run example in a docker jetty container
  8. cargo-maven plugin used to deploy example to a remote jetty container with cargo jetty app installed

reference tutorials

Very simple spring mvc JSP tutorial / example https://www.java4coding.com/contents/spring/spring-mvc-example

simple spring ReST example / tutorial https://spring.io/guides/tutorials/rest/ Building REST services with Spring

Spring Rest OpenAPI documentation https://www.baeldung.com/spring-rest-openapi-documentation

Docker-jetty-cargo - https://github.com/mthenw/docker-jetty-cargo/ Note my example is simpler and uses existing jetty container

Deploying Web Applications in Jetty https://www.baeldung.com/deploy-to-jetty

You might also want to look at using letsencrypt with docker:

example nginx letsencrypt: https://github.com/wmnnd/nginx-certbot

related tutorial: https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71

details

InteractiveMapSpringBoot

Example Interactive map web app based on Spring Boot and leaflet with JSP

This example is inspired by the example at

https://github.com/imaginalis/spring-boot-leaflet-starter

with the following changes:

  1. migrated to spring 5
  2. moved from leaflet to JSP
  3. data changed to use HSQLDB and not mysql for testing
  4. added openapi annotations

to run locally

mvn clean install

mvn spring-boot:run

UI is at http://localhost:8080/

open api annotations

Swagger / OpenAPI Test UI:

http://localhost:8080/swagger-ui/index.html

Swagger / OpenAPI yaml:

http://localhost:8080/api-docs

to run in docker

docker-compose up

to run in a remote docker

(NOTE - this example has been upgraded to use jetty 10 because there appears to be some stability issues with using cargo in the default jetty 9 container)

docker-compose -f docker-compose-deploy.yml build
docker-compose -f docker-compose-deploy.yml up -d

This Docker-compose script builds a jetty image using the referenced Dockerfile before running it. The Dockerfile adds the jetty cargo remote deployer app to thestandard jetty image.

if the cargo app is deployed you will get a command unknown repsonse from http://localhost:8080/cargo-jetty-deployer/

You can then deploy the application to a remote jetty using the cargo configuration in the pom

mvn clean install

mvn cargo:deploy

mvn cargo:undeploy

If you deploy the app it will show up at http://localhost:8080/

New deploy mechanism

The pom has changed to allow cargo to pick up properties from a properties file.

You need to copy deploy.properties.template to deploy.properties and change the values to match your site.

The mvn initialize goal reads the properties file so when deploying use the command

mvn initialize cargo:deploy

mvn initialize cargo:undeploy

or if doing a full build initialize is called after clean and before install


mvn clean install cargo:deploy