4
votes

I've a Spring Boot application of mine, which connects to a Postgres database. I've specified in application.properties the datasource url as -

spring.datasource.url=jdbc:postgresql://< server ip here >:5432/mydb

The jdbc url (jdbc:postgresql://< server ip here >:5432/) is actually stored in a separate external location which my application is able to read. Therefore, I want to specify only the database name in my properties file.

I don't want to pass the database name as some environment variable since it's not going to change.

I'm stuck at this point for quite some time now, how can I achieve the same?

3
wherever jdbc url (jdbc:postgresql://< server ip here >:5432/ is sored just append database name to that url string. If it is not going to change then you shouldn't face issues after appending database name to url.rdj7

3 Answers

2
votes

Add this in your application.properties file

spring.jpa.hibernate.ddl-auto=create\update\none
spring.datasource.url=jdbc:postgresql://host:port/db
spring.datasource.username=username
spring.datasource.password=password
0
votes

I finally implemented it this way.

Specified only database name in my application and created Datasource bean in a separate Spring Boot application (so that it can be reused across other projects as well).