Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Database configuration integration with Spring Boot #1481

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!-- Spring Boot Actuator displays build-related information
<!-- Spring Boot Actuator displays build-related information
if a META-INF/build-info.properties file is present -->
<goals>
<goal>build-info</goal>
Expand Down Expand Up @@ -378,7 +378,7 @@
<build>
<pluginManagement>
<plugins>
<!-- This plugin's configuration is used to store Eclipse m2e settings
<!-- This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
Expand Down Expand Up @@ -434,6 +434,30 @@
</pluginManagement>
</build>
</profile>
<profile>
<id>mysql</id>
<properties>
<spring-boot.run.profiles>mysql,docker-compose</spring-boot.run.profiles>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>postgres</id>
<properties>
<spring-boot.run.profiles>postgres,docker-compose</spring-boot.run.profiles>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
</project>
20 changes: 19 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,25 @@ 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.

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.
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Two options are available:

### Enable database via maven profile

Pass the profile for the corresponding database as an argument:

```bash
./mvnw spring-boot:run -Pmysql
```

or

```bash
./mvnw spring-boot:run -Ppostgres
```

### Manual configuration

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.

You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-docker-compose.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.docker.compose.profiles.active=${database}