.devcontainer | ||
.github/workflows | ||
.mvn/wrapper | ||
docker-kubernetes | ||
gradle/wrapper | ||
helm-ver/tanzu-se-petclinic | ||
src | ||
.editorconfig | ||
.gitignore | ||
.gitpod.yml | ||
.springjavaformatconfig | ||
build.gradle | ||
docker-compose.yml | ||
gradlew | ||
gradlew.bat | ||
LICENSE.txt | ||
mvnw | ||
mvnw.cmd | ||
pom.xml | ||
readme.md | ||
settings.gradle |
Spring PetClinic Sample Application 
Understanding the Spring Petclinic application with a few diagrams
Running petclinic locally
Petclinic is a Spring Boot application built using Maven or Gradle. You can build a jar file and run it from the command line (it should work just as well with Java 11 or newer):
git clone https://github.com/i386kernel/tanzu-SE-spring-petclinic.git
cd spring-petclinic
./mvnw package
java -jar target/*.jar
You can then access petclinic here: http://localhost:8080/
Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this):
./mvnw spring-boot:run
NOTE: Windows users should set
git config core.autocrlf true
to avoid format assertions failing the build (use--global
to set that flag globally).
NOTE: If you prefer to use Gradle, you can build the app using
./gradlew build
and look for the jar file inbuild/libs
.
Building a Container
There is no Dockerfile
in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
./mvnw spring-boot:build-image
Run in Docker
docker run -p 8080:8080 -d spring-petclinic:2.7.3
Run in Kubernetes
kubectl apply -f https://raw.githubusercontent.com/i386kernel/tanzu-SE-spring-petclinic/main/docker-kubernetes/kube-manifest.yml
Database configuration
In its default configuration, Petclinic uses an in-memory database (H2) which
gets populated at startup with data. The h2 console is automatically exposed at http://localhost:8080/h2-console
and it is possible to inspect the content of the database using the jdbc:h2:mem:testdb
url.
A similar setup is provided for MySQL and PostgreSQL in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: spring.profiles.active=mysql
for MySQL or spring.profiles.active=postgres
for PostgreSQL.
You could start MySQL or PostgreSQL locally with whatever installer works for your OS, or with docker:
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
or
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:14.1
Further documentation is provided for MySQL and for PostgreSQL.