Spring application.yml, datasource and profile.

170 views
Skip to first unread message

Rick

unread,
Jun 5, 2018, 12:31:06 PM6/5/18
to Ebean ORM
Hi, 

I am using laster ebean 11.15.2 and using application.yml and application-test.yml for datasource and  configuration.

Want to which datasource ebean will use when my application.yml contains multi-profiles. And how to let ebean use different datasource profile according one jvm environment parameters. 

Thank you very much.

Here is my application.yml:

---
spring:
  profiles: development

datasource:
  db:
    username: test
    password: test
    url: jdbc:postgresql://localhost:6432/test_ex
    driver: org.postgresql.Driver

---
spring:
  profiles: production

datasource:
  db:
    username: test
    password: test
    url: jdbc:postgresql://localhost:5432/production_db
    driver: org.postgresql.Driver

Rob Bygrave

unread,
Jun 5, 2018, 11:36:32 PM6/5/18
to ebean@googlegroups

Here is my application.yml:

I am thinking that this application.yml is packaged with the application (src/main/resources) and specifically it is not externally supplied.  Is that correct?

Today Ebean is not aware of spring profiles - so what you have above isn't expected to work per say. Instead, what would work is to have src/test/resources/application-test.yml ... containing the below (and this would generally be  the configuration used when running tests locally):

datasource:
  db:
    username: test
    password: test
    url: jdbc:postgresql://localhost:6432/test_ex
    driver: org.postgresql.Driver



 how to let ebean use different datasource profile according one jvm environment parameter

Ebean reads/uses the "DB" environment variable so you could have multiple named datasource's and control which one is used via the DB environment variable.



Note that the values in the properties file can be expressions like:
username: ${dbUserName:test}
... so then you can override specific parameters. 



--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rick

unread,
Jun 6, 2018, 1:17:10 AM6/6/18
to eb...@googlegroups.com
Hi Rob,

Your understand for the applicaiton.yml path is correct.
Then I was confused because in the example-java8 project there is an applicaiton.yml under src/main/resources and there are datasource properties!

Reply all
Reply to author
Forward
0 new messages