user1854373
user1854373

Reputation: 83

How to pass database name explicitly in Spring Boot Configuration?

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?

Upvotes: 5

Views: 15657

Answers (3)

user1854373
user1854373

Reputation: 83

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).

Upvotes: 0

Vikram Saini
Vikram Saini

Reputation: 2769

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

Upvotes: 2

Related Questions