Updates to reamefile and some clean up code

This commit is contained in:
Renzo Vallejos 2024-09-25 12:11:14 -07:00
parent a9e2decb39
commit ce43d6f1b1
3 changed files with 17 additions and 11 deletions

View file

@ -43,20 +43,20 @@ Our issue tracker is available [here](https://github.com/spring-projects/spring-
## Database configuration
In its default configuration, Petclinic uses an in-memory database (H2) which
gets populated at startup with data. The h2 console is exposed at `http://localhost:8080/h2-console`,
and it is possible to inspect the content of the database using the `jdbc:h2:mem:<uuid>` URL. The UUID is printed at startup to the console.
By default, Spring PetClinic uses an in-memory H2 database that gets populated with sample data during startup. The H2 console can be accessed at http://localhost:8080/h2-console. You can inspect the database using the following JDBC URL: jdbc:h2:mem:<uuid> where the UUID is printed at startup.
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL. See the [Spring Boot documentation](https://docs.spring.io/spring-boot/how-to/properties-and-configuration.html#howto.properties-and-configuration.set-active-spring-profiles) for more detail on how to set the active profile.
If you need a persistent database, MySQL and PostgreSQL configurations are also supported. When switching databases, you'll need to activate the appropriate profile by setting spring.profiles.active=mysql or spring.profiles.active=postgres.
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
Heres how to start MySQL or PostgreSQL with Docker:
## MySQL
```bash
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.4
```
or
## PostgreSQL
```bash
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:16.3
```
@ -64,7 +64,7 @@ docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)
and [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt).
Instead of vanilla `docker` you can also use the provided `docker-compose.yml` file to start the database containers. Each one has a profile just like the Spring profile:
Alternatively, use the provided docker-compose.yml file for a more streamlined setup:
```bash
docker-compose --profile mysql up
@ -77,8 +77,14 @@ docker-compose --profile postgres up
```
## Test Applications
`MySqlTestApplication`
At development time we recommend you use the test applications set up as `main()` methods in `PetClinicIntegrationTests` (using the default H2 database and also adding Spring Boot Devtools), `MySqlTestApplication` and `PostgresIntegrationTests`. These are set up so that you can run the apps in your IDE to get fast feedback and also run the same classes as integration tests against the respective database. The MySql integration tests use Testcontainers to start the database in a Docker container, and the Postgres tests use Docker Compose to do the same thing.
We recommend running the test applications configured in the following classes for faster feedback during development:
`PetClinicIntegrationTests`(using the default H2 database and Spring Boot DevTools)
`MySqlTestApplication` (for MySQL)
`PostgresIntegrationTests` (for PostgreSQL)
These classes are designed to help you test the application easily in your IDE and can also be run as integration tests. MySQL tests use Testcontainers to manage the database, while PostgreSQL tests rely on Docker Compose.
## Compiling the CSS
@ -133,10 +139,10 @@ The following items should be installed in your system:
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
## Interesting Spring Petclinic branches and forks
## Explore Other Forks and Branches
The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
repository is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in the GitHub org
[spring-petclinic](https://github.com/spring-petclinic). If you are interested in using a different technology stack to implement the Pet Clinic, please join the community there.

View file

@ -20,7 +20,7 @@ import jakarta.persistence.MappedSuperclass;
import jakarta.validation.constraints.NotBlank;
/**
* Simple JavaBean domain object representing an person.
* Simple JavaBean domain object representing a person.
*
* @author Ken Krebs
*/

View file

@ -24,5 +24,5 @@ logging.level.org.springframework=INFO
# Maximum time static resources should be cached
spring.web.resources.cache.cachecontrol.max-age=12h
#Used for testing the app with another port. In this case I used port 8095
#Used for testing the app with another port. In this case I used port 8095 for testing
#server.port = 8095