{"id":20567409,"url":"https://github.com/sombriks/sample-spring-multiple-databases","last_synced_at":"2026-04-20T19:04:58.036Z","repository":{"id":63528882,"uuid":"568445968","full_name":"sombriks/sample-spring-multiple-databases","owner":"sombriks","description":"sample-spring-multiple-databases","archived":false,"fork":false,"pushed_at":"2022-11-20T20:13:19.000Z","size":77,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T09:23:04.658Z","etag":null,"topics":["configuration-management","database","java","spring-boot"],"latest_commit_sha":null,"homepage":"https://sombriks.com.br/#/blog/0037-two-databases-on-spring-boot.md","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sombriks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-20T15:02:56.000Z","updated_at":"2023-03-05T02:08:23.000Z","dependencies_parsed_at":"2023-01-23T16:01:29.478Z","dependency_job_id":null,"html_url":"https://github.com/sombriks/sample-spring-multiple-databases","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sombriks/sample-spring-multiple-databases","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sombriks%2Fsample-spring-multiple-databases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sombriks%2Fsample-spring-multiple-databases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sombriks%2Fsample-spring-multiple-databases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sombriks%2Fsample-spring-multiple-databases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sombriks","download_url":"https://codeload.github.com/sombriks/sample-spring-multiple-databases/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sombriks%2Fsample-spring-multiple-databases/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32061259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration-management","database","java","spring-boot"],"created_at":"2024-11-16T04:46:36.985Z","updated_at":"2026-04-20T19:04:58.007Z","avatar_url":"https://github.com/sombriks.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Getting Started\n\nConfigure one spring boot datasource is a matter of simply declare the correct\nproperties into [application.properties](src/main/resources/application.properties)\nfile and let autoconfiguration work.\n\nBut things are different when we need a second one.\n\nThis project tries to sample how to configure multiple databases (enabling jdb,\njpa and spring repositories) in a single project.\n\n## General steps\n\n- define two sets of datasource configurations in properties file\n- for each database, define distinct package sets for entities and repositories\n- define two @Configuration classes defining these components:\n  - DataSourceProperties\n  - DataSource\n  - LocalContainerEntityManagerFactoryBean\n  - PlatformTransactionManager\n- starting from java 11, add `--add-modules java.sql` in compiler options\n- one of those configurations MUST annotate beans as @Primary\n\n## Research sources\n\n- \u003chttps://mmafrar.medium.com/configuring-multiple-data-sources-with-spring-boot-2-and-spring-data-jpa-8e236844e80f\u003e\n- \u003chttps://www.baeldung.com/sql-logging-spring-boot#2-via-loggers\u003e\n- \u003chttps://www.baeldung.com/java-in-memory-databases\u003e\n- \u003chttps://www.baeldung.com/spring-data-jpa-multiple-databases\u003e\n- \u003chttps://stackoverflow.com/questions/31045955/using-configurationproperties-to-fill-map-in-generic-way\u003e\n\n## Reference Documentation\n\nFor further reference, please consider the following sections:\n\n* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)\n* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.6.13/maven-plugin/reference/html/)\n* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.6.13/maven-plugin/reference/html/#build-image)\n* [Rest Repositories](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#howto.data-access.exposing-spring-data-repositories-as-rest)\n* [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#appendix.configuration-metadata.annotation-processor)\n* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#data.sql.jpa-and-spring-data)\n* [JDBC API](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#data.sql)\n* [Spring Web](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#web)\n* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#using.devtools)\n* [Spring Reactive Web](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#web.reactive)\n\n## Guides\n\nThe following guides illustrate how to use some features concretely:\n\n* [Accessing JPA Data with REST](https://spring.io/guides/gs/accessing-data-rest/)\n* [Accessing Neo4j Data with REST](https://spring.io/guides/gs/accessing-neo4j-data-rest/)\n* [Accessing MongoDB Data with REST](https://spring.io/guides/gs/accessing-mongodb-data-rest/)\n* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)\n* [Accessing Relational Data using JDBC with Spring](https://spring.io/guides/gs/relational-data-access/)\n* [Managing Transactions](https://spring.io/guides/gs/managing-transactions/)\n* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)\n* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)\n* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)\n* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsombriks%2Fsample-spring-multiple-databases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsombriks%2Fsample-spring-multiple-databases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsombriks%2Fsample-spring-multiple-databases/lists"}