Change the database in the fullstack project template

Hi guys,

I am using the fullstack project template in the 2023.06-ext1 version, which has an H2 database in its standard configuration.
Id like to change the database to a postgres and found in the documentation that only a few properties have to be changed.
From the documentation page GetA12 Login I got following properties and configured them:

spring.datasource.dataservices.url=jdbc:postgresql://localhost:5432/testproject
spring.datasource.dataservices.driverClassName=org.postgresql.Driver
spring.datasource.dataservices.name=testproject
spring.datasource.dataservices.username=postgres
spring.datasource.dataservices.password=postgres
spring.jpa.database=POSTGRESQL
spring.datasource.hikari.connectionTimeout=30000
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

The problem is that the application is still starting with an H2 database. Besides that there are no errors logged.

2023-09-28T15:56:19.286+02:00  INFO 22768 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8082 (http)
2023-09-28T15:56:19.298+02:00  INFO 22768 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-09-28T15:56:19.299+02:00  INFO 22768 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.8]
2023-09-28T15:56:19.433+02:00  INFO 22768 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-09-28T15:56:19.434+02:00  INFO 22768 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4370 ms
2023-09-28T15:56:19.628+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-09-28T15:56:19.927+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:faa87201-8b70-4c2c-8483-06c848434764 user=SA
2023-09-28T15:56:19.932+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-09-28T15:56:19.941+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
2023-09-28T15:56:19.946+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-2 - Added connection conn1: url=jdbc:h2:mem:contentstore user=SA
2023-09-28T15:56:19.947+02:00  INFO 22768 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed.
2023-09-28T15:56:19.947+02:00  INFO 22768 --- [           main] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/console/'. Databases available at 'jdbc:h2:mem:faa87201-8b70-4c2c-8483-06c848434764', 'jdbc:h2:mem:contentstore', 'jdbc:h2:mem:faa87201-8b70-4c2c-8483-06c848434764'

I also tried with the normal spring properties

spring.jpa.database=POSTGRESQL
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/testproject
spring.datasource.username=postgres
spring.datasource.password=postgres

And with a combination of both, but it’s still only using H2.

Maybe I am missing something?

Hi, Could you please provide which version of data-services you’re working on exactly?

Hi,
After changing the config for using Postgres, do you change the active profile for running the project with Postgres config?

Moin,
you have to also provide the local-db spring profile when you start the server, additionally to the dev.

Hey, thanks for the response!
I’ve tried starting the server with dev and local-db, but still using H2 unfortunately.

2023-09-29T14:50:31.692+02:00  INFO 14712 --- [           main] m.a.t.s.ProjectTemplateServerApplication : The following 2 profiles are active: "dev", "local-db"
...
2023-09-29T14:50:36.535+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-09-29T14:50:36.851+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:f4a95b6a-dccd-4722-9a17-69e77511c4e6 user=SA
2023-09-29T14:50:36.852+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-09-29T14:50:36.865+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
2023-09-29T14:50:36.867+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-2 - Added connection conn1: url=jdbc:h2:mem:contentstore user=SA
2023-09-29T14:50:36.867+02:00  INFO 14712 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed.
2023-09-29T14:50:36.867+02:00  INFO 14712 --- [           main] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/console/'. Databases available at 'jdbc:h2:mem:f4a95b6a-dccd-4722-9a17-69e77511c4e6', 'jdbc:h2:mem:contentstore', 'jdbc:h2:mem:f4a95b6a-dccd-4722-9a17-69e77511c4e6'

Hey, no, I don’t change the active profile, because I put the configuration for the database just inside the standard spring config application.properties, which should be loaded regardless. Additionally, I am starting with the dev profile.

Hey! Sure, I am using A12 2023.06-ext1 with data-services 36.0.1

Hi @raffael-broad-linden,
I’ve noticed that in data-services 36.0.1, all spring application.properties for the database is now going with a prefix spring.datasources (with the s) instead of spring.datasource.
In your case, the correct configs possibly be

# Postgres
spring.datasources.dataservices.driver-class-name=org.postgresql.Driver
spring.datasources.dataservices.jpa.database=POSTGRESQL
spring.datasources.dataservices.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
# TODO: Replace these placeholders with yours
spring.datasources.dataservices.username=your-db-username
spring.datasources.dataservices.password=your-db-password
spring.datasources.dataservices.url=jdbc:postgresql://localhost:5432/your-db-name

Hey, thanks for the response and that solved my problem.
The documentation for my A12 version says datasource without the s, but with datasources works, thank you for pointing that out!