5

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?

1
  • 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. Commented Jun 4, 2018 at 7:31

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Vikram...By specifying spring.datasource.url=jdbc:postgresql://host:port/db .. Application works. Please read the question again to know how exactly I want to implement.
2

Have you tried using ${var} syntax like:

spring.datasource.url=jdbc:postgresql://${server-ip}:5432/mydb

See:

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.