Connect Spring Boot To Database
Spring Boot Settings Change
- Add this to your production profile (or whatever profile you use in your deployment):
application.yaml
spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: false
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
datasource:
url: jdbc:postgresql://postgres.db:5432/appdb
username: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
driver-class-name: org.postgresql.Driver
- Add this to your
deployment.yaml
deployment.yaml
spec:
template:
spec:
containers:
- env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_PASSWORD
Add postgres-secret
- go to https://rancher.sau-portal.de/dashboard/c/local/explorer/secret/create
- click
Opaque - Enter
postgres-secretas the Name - Add a
POSTGRES_PASSWORDandPOSTGRES_USERkey - Your initial credentials were given to each PO by Team 15
note
If you have problems with your credentials notify team 15
Your application should now use the production database. 🥳
note
If you initialize test data on each start up you need to deactivate that as this will continue to happen on each start of your pod. After some time your db will be cluttered with useless data.