Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

549
Views
Multiple properties in YAML file Spring Boot
spring: 
   profiles: dev
spring.datasource: 
        driver-class-name: 
        password: ~
        url: ~
        username: ~
--- 
secdb: 
  profiles: dev
spring.datasource: 
       driver-class-name: ~
       password: ~
       url: ~
       username: ~
---

I have above two properties declared as shown in the application.yml file but when I use it in implementation class as follows.

@Value("${spring.datasource.url}")
private String URL;

it works and picks up the url from YML file. but when I do as follows

@Value("${secdb.spring.datasource.url}")
private String URL;

it fails at spring boot start saying

Could not resolve placeholder 'secdb.spring.datasource.url' in value...

As, I am at beginner level. YML may be wrong but my intention is to have two data sources in the YML file and use the second one for one JDBC connection other one is default. Please, guide me through the mistake

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have made two mistakes in your yaml file.

  1. Don't use space before ---.
  2. Before your first spring.datasource:, there is a space. It indicates spring.datasource: is a subproperty of spring:.
  3. @Value("${secdb.spring.datasource.url}") is absolutely not the right way. Even you active secdb, you also need to get the value like @Value("${spring.datasource.url}").
  4. I do't suggest you to use Spring profiles like secdb: profiles: dev. It's not a familiar way. You can use it like spring: profiles: secdb and active it just like spring.profiles.active=secdb. Or if you insist to use it that way, you need to active it like spring.profiles.active=secdb.

After all, if you want to use Spring profiles properties, you need to active it just like $ java -jar -Dspring.profiles.active=production or add spring.profiles.active=production in application.properties.

I suggest you to read this document in detail.

I will be glad if it helps.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!