{"id":16178863,"url":"https://github.com/yuanwenqing/springboot-support","last_synced_at":"2026-05-08T15:34:17.798Z","repository":{"id":118004211,"uuid":"146431484","full_name":"YuanWenqing/springboot-support","owner":"YuanWenqing","description":"some extension and support for spring boot","archived":false,"fork":false,"pushed_at":"2018-09-06T02:44:39.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T11:47:00.863Z","etag":null,"topics":["datasource","multi-datasource","spring","spring-boot","spring-boot-extend"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YuanWenqing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-28T10:34:04.000Z","updated_at":"2018-09-04T04:56:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"21ea4324-daf8-490e-80b0-0dd64e2da9fc","html_url":"https://github.com/YuanWenqing/springboot-support","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/YuanWenqing/springboot-support","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuanWenqing%2Fspringboot-support","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuanWenqing%2Fspringboot-support/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuanWenqing%2Fspringboot-support/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuanWenqing%2Fspringboot-support/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YuanWenqing","download_url":"https://codeload.github.com/YuanWenqing/springboot-support/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuanWenqing%2Fspringboot-support/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263699742,"owners_count":23497962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["datasource","multi-datasource","spring","spring-boot","spring-boot-extend"],"created_at":"2024-10-10T05:24:44.538Z","updated_at":"2026-05-08T15:34:12.772Z","avatar_url":"https://github.com/YuanWenqing.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# springboot-support\nsome extended supports for SpringBoot\n\n## multi-datasource\n\nSupport multi-datasource for SpringBoot.\n\n### How To Enable Multi-DataSource Support?\n\nJust do it in a SpringBoot way:\n\n~~~java\n@Configuration\n@EnableMultiDataSource\npublic class XXXConfiguration {\n  // code...\n}\n~~~\n\nor\n\n~~~java\n@SpringBootApplication\n@EnableMultiDataSource\npublic class XXXApplication {\n  // code...\n}\n~~~\n\nIn purpose to specify your configuration of multi-datasource, inside `EnableMultiDataSource` you can change:\n\n* `location`: location of configuration properties, default `classpath:application.properties`.\n* `prefix`: prefix of configuration, default `multi-datasource.multi`.\n* `loader`: class of loader to load configuration properties, default `DefaultPropertiesLoader`; If some ConfigurationService, like Spring Cloud Config or Aliyun ACM, is in use, change `loader` to a customized loader class implementing `PropertiesLoader` interface to load it in your way.  \n\n### How To Configure Multi-DataSource?\n\nConfiguration properties is parsed by `PropertiesParser`. As a convention, every item will be treated in a `\u003cprefix\u003e.\u003cname\u003e.\u003cconfig\u003e.\u003cproperty\u003e` pattern:\n\n* `prefix`: `prefix` defined in `EnableMultiDataSource`\n* `name`: base name of DataSource and JdbcTemplate beans, thus generating bean names in pattern `\u003cname\u003eDataSource` and `\u003cname\u003eJdbcTemplate`\n* `config`: a sub-name for detail config properties of DataSource, candidates is below\n  * `datasource`: basic config properties, bind to `DataSourceProperties`\n  * `hikari`: Hikari config, bind to `com.zaxxer.hikari.HikariDataSource`\n  * `tomcat`: Tomcat config, bind to `org.apache.tomcat.jdbc.pool.DataSource`\n  * `dbcp2`: Dbcp2 config, bind to `org.apache.commons.dbcp2.BasicDataSource`\n* `property`: property name in `DataSourceProperties`; We reuse utilized classes `DataSourceProperties` and `DataSourceBuilder` in SpringBoot to construct DataSource and JdbcTemplate\n\nType of DataSource will be determined by SpringBoot automatically if not specified in properties,\njust like `spring-boot-starter-jdbc` does.\n\nExample:\n\n~~~properties\nmulti-datasource.multi.a.datasource.url = jdbc:mysql://localhost:3306/test\nmulti-datasource.multi.a.datasource.username=test\nmulti-datasource.multi.a.datasource.password=123456\nmulti-datasource.multi.a.datasource.driver-class-name=com.mysql.cj.jdbc.Driver\n\nmulti-datasource.multi.b.datasource.url = jdbc:mysql://localhost:3306/test\nmulti-datasource.multi.b.datasource.username=test\nmulti-datasource.multi.b.datasource.password=123456\nmulti-datasource.multi.b.datasource.driver-class-name=com.mysql.cj.jdbc.Driver\nmulti-datasource.multi.b.hikari.maximum-pool-size = 3\n~~~\n\nThis will lead to construction of:\n\n* 2 DataSources with bean names: `aDataSource` and `bDataSource`\n* 2 JdbcTemplates with bean names: `aJdbcTemplate` and `bJdbcTemplate`\n\n### How To Inject DataSource/JdbcTemplate?\n\nBeans depending on a DataSource or JdbcTemplate must be annotated by `DataSourceRouting`,\nand `value` should be one of base names parsed from configuration properties.\nBesides, to accept DataSource or JdbcTemplate specified by `DataSourceRouting`,\nbean also must satisfied one of the following convention: \n\n* implement interface `DataSourceAware` or `JdbcTemplateAware`.\n* own a method named as `setDataSource` or `setJdbcTemplate`.\n\nExample:\n\n~~~java\n@DataSourceRouting(\"a\")\npublic class JdbcTemplateAwareBean implements JdbcTemplateAware {\n  private JdbcTemplate jdbcTemplate;\n  @Override\n  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {\n    this.jdbcTemplate = jdbcTemplate;\n  }\n}\n~~~\n\nor\n\n~~~java\n@DataSourceRouting(\"a\")\npublic class JdbcTemplateSetterBean {\n  private JdbcTemplate jdbcTemplate;\n  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {\n    this.jdbcTemplate = jdbcTemplate;\n  }\n}\n~~~\n\nInjection of DataSource and JdbcTemplate is processed by `DataSourceRoutingPostProcessor`,\nwhich will detect interfaces and methods introduced above and do the injection. \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanwenqing%2Fspringboot-support","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanwenqing%2Fspringboot-support","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanwenqing%2Fspringboot-support/lists"}