<commit_before>---
layout: post
title:  "Spring boot: YAML multiple datasources"
date:   2015-11-22 23:56:45
comments: true
toc: false
categories:
- blog
permalink: spring-yml-datasources
description: How to configure multiple datasources in Srping boot using YAML.
---

In this example we will see how to config two datasources on different environments (development, test, production)
using a YAML config file.

## application.yml

In order to select the environment I used profiles. Also, we can see that two datasources are defined for each
env. However it's not gonna to work without the few modifications described next section.

{% highlight yaml%}
spring:
  profiles.active: development

---
spring:
  profiles: development
datasource:
  base-person:
      url: jdbc:oracle:thin:@db_person_dev
      username: username
      password: <PASSWORD>
      driver-class-name: oracle.jdbc.OracleDriver
      validationQuery: "SELECT 1 FROM dual"
  base-contrat:
      url: jdbc:oracle:thin:@db_contract_dev
      username: username
      password: <PASSWORD>
      driver-class-name: oracle.jdbc.OracleDriver
      validationQuery: "SELECT 1 FROM dual"
<commit_msg>typo 4 multiple datasources<commit_after>---
layout: post
title:  "Spring boot: YAML multiple datasources"
date:   2015-11-22 23:56:45
comments: true
toc: false
categories:
- blog
permalink: spring-yml-datasources
description: How to configure multiple datasources in Srping boot using YAML.
---

In this example we will see how to config two datasources on different environments (development, test, production)
using a YAML config file.

## application.yml

In order to select the environment I used profiles. Then, we can see that datasources configured on each
environments.

{% highlight yaml%}
spring:
  profiles.active: development

---
spring:
  profiles: development
datasource:
  base-person:
      url: jdbc:oracle:thin:@db_person_dev
      username: username
      password: <PASSWORD>
      driver-class-name: oracle.jdbc.OracleDriver
      validationQuery: "SELECT 1 FROM dual"
  base-contrat:
      url: jdbc:oracle:thin:@db_contract_dev
      username: username
      password: <PASSWORD>
      driver-class-name: oracle.jdbc.OracleDriver
      validationQuery: "SELECT 1 FROM dual"

{'fraction_non_alphanumeric': 0.08031774051191527, 'fraction_numerical': 0.014563106796116505, 'mean_word_length': 3.906926406926407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1078963', 'n_tokens_mistral': 709, 'n_tokens_neox': 641, 'n_words': 239}