Vikash
Vikash

Reputation: 711

Spring Boot: Datasource properties

I have a confusion regarding datasource autoconfiguration in Spring-boot. From what I have read, we have to specify the datasource properties in the form spring.datasource.*. But my application code works fine if I supply property name in the form SPRING_DATASOURCE_*. Is there any reason that I am missing, due to which it works? Please clarify.

Upvotes: 0

Views: 257

Answers (2)

Mikhail Kopylov
Mikhail Kopylov

Reputation: 2078

Spring Boot has so-called Relaxed Binding https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding which allows you to define configuration in different ways:

  • acme.my-project.person.first-name acme.myProject.person.firstName
  • acme.myProject.person.firstName
  • acme.my_project.person.first_name
  • ACME_MYPROJECT_PERSON_FIRSTNAME

The latter is often used when passed via environment variables.

Upvotes: 2

Mark Bramnik
Mark Bramnik

Reputation: 42541

I think You've come across a feature of spring boot called Relaxed Binding.

It allows using some "relaxed" rules for binding to ConfigurationProperties. So essentially both ways of definition have the same effect in your application.

Here you can find a link to the relevant chapter in the official documentation

Upvotes: 2

Related Questions