Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

552
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda