actuator added & spring profiles introduced

This commit is contained in:
Wojtek Krzywiec
2020-06-07 23:13:32 +02:00
parent 62960ef444
commit 428d281e38
6 changed files with 78 additions and 23 deletions

View File

@@ -8,4 +8,4 @@ RUN mvn -B -f pom.xml clean package -DskipTests
FROM openjdk:11-jdk-slim
COPY --from=build /workspace/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
ENTRYPOINT ["java","-jar","app.jar", "--spring.profiles.active=prod"]

View File

@@ -19,14 +19,23 @@ In the terminal run the following command:
$ docker-compose up
```
#### Using Maven
#### Using Maven (with H2 or local Postgres database)
First make sure that you adjust the configuration file - `src/main/resources/application.yml` with connection details to your database.
First compile an application:
Then, in the terminal run the following command:
```console
$ mvn clean package
$ mvn spring-boot:run
```
Then, you have two options either run it with H2 database or with local Postgres database. For first approach just run:
```console
$ mvn spring-boot:run
```
For a second option, check in the configuration file - `src/main/resources/application.yml` for profile *local-postgres* if connection details are correct and if so, run the command:
```console
$ mvn spring-boot:run -P local-postgres
```
#### Inside IntelliJ (with H2 or Postgres database)

31
pom.xml
View File

@@ -33,6 +33,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@@ -186,6 +190,33 @@
</build>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<active-profiles>default</active-profiles>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<active-profiles>prod</active-profiles>
</properties>
</profile>
<profile>
<id>local-postgres</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<active-profiles>local-postgres</active-profiles>
</properties>
</profile>
<profile>
<id>component-test</id>
<build>

View File

@@ -1,9 +0,0 @@
spring:
application:
name: library
datasource:
url: jdbc:h2:mem:testdb
driverClassName: org.h2.Driver
username: sa
password: password
jpa.database-platform: org.hibernate.dialect.H2Dialect

View File

@@ -1,9 +0,0 @@
spring:
application:
name: library
datasource:
url: jdbc:postgresql://localhost:5432/library
driverClassName: org.postgresql.Driver
username: library
password: library
jpa.database-platform: org.hibernate.dialect.PostgreSQL9Dialect

View File

@@ -1,6 +1,39 @@
spring:
application:
name: library
profiles:
active: @active-profiles@
management:
endpoints:
web:
exposure:
include: "*"
---
spring:
profiles: default
datasource:
url: jdbc:h2:mem:testdb
driverClassName: org.h2.Driver
username: sa
password: password
jpa.database-platform: org.hibernate.dialect.H2Dialect
---
spring:
profiles: local-postgres
datasource:
url: jdbc:postgresql://localhost:5432/library
driverClassName: org.postgresql.Driver
username: library
password: library
jpa.database-platform: org.hibernate.dialect.PostgreSQL9Dialect
---
spring:
profiles: prod
datasource:
url: jdbc:postgresql://${POSTGRES_SERVER}:5432/${POSTGRES_DB}
driverClassName: org.postgresql.Driver