René's URL Explorer Experiment


Title: [xxx] 整合MyBatis-plus的dynamic多数据源发生Too many connections · Issue #847 · APIJSON/APIJSON · GitHub

Open Graph Title: [xxx] 整合MyBatis-plus的dynamic多数据源发生Too many connections · Issue #847 · APIJSON/APIJSON

X Title: [xxx] 整合MyBatis-plus的dynamic多数据源发生Too many connections · Issue #847 · APIJSON/APIJSON

Description: Description 我在使用多数据源的情况下,尝试整合MyBatis-plus的多数据源的情况下出现了点问题,是这样的,我们项目中除了使用apijson外,也需要自己进行写一些增删改的接口,而且也要支持多数据源,所以这里我尝试整合MyBatis-plus的多数据源,我初步是整合成功了,通过apijson和自己写的接口,都可进行多数据源的增删改查,但是出现了一些问题,当项目使用一段时间,控制台就会报错:Too many connections(MySQL 错误码 10...

Open Graph Description: Description 我在使用多数据源的情况下,尝试整合MyBatis-plus的多数据源的情况下出现了点问题,是这样的,我们项目中除了使用apijson外,也需要自己进行写一些增删改的接口,而且也要支持多数据源,所以这里我尝试整合MyBatis-plus的多数据源,我初步是整合成功了,通过apijson和自己写的接口,都可进行多数据源的增删改查,但是出现了一些问题,当项目使用一段时间,控...

X Description: Description 我在使用多数据源的情况下,尝试整合MyBatis-plus的多数据源的情况下出现了点问题,是这样的,我们项目中除了使用apijson外,也需要自己进行写一些增删改的接口,而且也要支持多数据源,所以这里我尝试整合MyBatis-plus的多数据源,我初步是整合成功了,通过apijson和自己写的接口,都可进行多数据源的增删改查,但是出现了一些问题,当项目使用一段时间,控...

Opengraph URL: https://github.com/APIJSON/APIJSON/issues/847

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[xxx] 整合MyBatis-plus的dynamic多数据源发生Too many connections","articleBody":"### Description\n\n我在使用多数据源的情况下,尝试整合MyBatis-plus的多数据源的情况下出现了点问题,是这样的,我们项目中除了使用apijson外,也需要自己进行写一些增删改的接口,而且也要支持多数据源,所以这里我尝试整合MyBatis-plus的多数据源,我初步是整合成功了,通过apijson和自己写的接口,都可进行多数据源的增删改查,但是出现了一些问题,当项目使用一段时间,控制台就会报错:Too many connections(MySQL 错误码 1040)就是数据库连接太多了,比如我通过一直调用apijson的get方法,调用一两百次,就会复现这个问题,我怀疑是没有正常关闭连接的问题,但是我始终找不到问题点在哪里,为了实现两者整合,我重写了DemoSQLExecutor的getConnection方法,以可以从MyBatis-plus的多数据源地方获取DataSource,然后取消了原本的通过DemoDataSourceConfig的@Bean方式注入DruidDataSource的代码,然后修改了一下配置,改动如下\n请问Tommy哥,这种情况有办法解决吗?\n环境:Java21+SpringBoot3.2.5+MySQL8.0.24+dynamic-datasource4.3.1(MyBatis-plus的多数据源包)\n\n重写的DemoSQLExecutor的getConnection方法\n\t@Override\n\tpublic Connection getConnection(SQLConfig config) throws Exception {\n\t\tString key = config.getDatasource() + \"-\" + config.getDatabase();\n\t\tConnection c = connectionMap.get(key);\n\t\tif (c == null || c.isClosed()) {\n\n\t\t\t// 获取 Spring 上下文和 Environment\n\t\t\tApplicationContext ctx = DemoApplication.getApplicationContext();\n\t\t\tif (ctx == null) {\n\t\t\t\tthrow new IllegalStateException(\"无法获取 Spring ApplicationContext\");\n\t\t\t}\n\t\t\tEnvironment env = ctx.getEnvironment();\n\n\t\t\t// 3) 获取要使用的 dataSource 名(前端通过@datasource来指定)\n\t\t\tString requested = config.getDatasource();\n\t\t\tDataSource ds = null;\n\n\t\t\tMap\u003cString, DataSource> provided = new HashMap\u003c>();\n\t\t\t// 如果容器有 DynamicDataSourceProvider bean(starter 情况),直接取出 provider 管理的 map\n\t\t\tif (ctx.getBeanNamesForType(DynamicDataSourceProvider.class).length > 0) {\n\t\t\t\tDynamicDataSourceProvider provider = ctx.getBean(DynamicDataSourceProvider.class);\n\t\t\t\tprovided = provider.loadDataSources();\n\t\t\t\tds = provided.get(requested);\n\t\t\t}\n\n\t\t\t// 4) 如果没找到,尝试从配置读取默认数据源名(spring.datasource.dynamic.primary)\n\t\t\tif (ds == null) {\n\t\t\t\tString primaryName = null;\n\t\t\t\ttry {\n\t\t\t\t\tprimaryName = env.getProperty(\"spring.datasource.dynamic.primary\");\n\t\t\t\t} catch (Throwable ignored) {}\n\t\t\t\tif (primaryName != null && !primaryName.isBlank()) {\n\t\t\t\t\tds = provided.get(primaryName);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 5) 最后兜底:如果 ds 仍然为空且 dsMap 只有一个元素,则取唯一那个\n\t\t\tif (ds == null && provided.size() == 1) {\n\t\t\t\tds = provided.values().iterator().next();\n\t\t\t}\n\n\t\t\t// 7) 获取连接并缓存(保留原先的 connectionMap 逻辑)\n\t\t\tconnectionMap.put(key, ds == null ? null : ds.getConnection());\n\t\t}\n\n\t\t// 保持原来的逻辑:必须最后执行 super.getConnection(config)\n\t\treturn super.getConnection(config);\n\t}\n\n配置:\nspring: \n  datasource:\n    dynamic:\n      primary: druid   # 指定默认数据源名称\n      datasource:\n        druid:\n          driverClassName: com.mysql.cj.jdbc.Driver\n          url: jdbc:mysql://localhost:3306/office_automation?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8\n          username: root\n          password: root\n          type: com.alibaba.druid.pool.DruidDataSource\n        druid-test:\n          driverClassName: com.mysql.cj.jdbc.Driver\n          url: jdbc:mysql://14.70.22.777:33336/office_automation?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8\n          username: ENC(fXGOMv7Vggup2KAbAyHoI6Mzd7lqblJdxi1CSt8CZvAjGHen5rAj6HiwKt5W)\n          password: ENC(n24kDLyLtsv2HJCpwhKzIJycd/UD+NYy88c2haiS7mIUj0S/2Am8sQ==)\n          type: com.alibaba.druid.pool.DruidDataSource\n\nMyBatis-plus的多数据源依赖包的坐标:\n\u003c!-- 多数据源 -->\n\t\t\u003cdependency>\n\t\t\t\u003cgroupId>com.baomidou\u003c/groupId>\n\t\t\t\u003cartifactId>dynamic-datasource-spring-boot3-starter\u003c/artifactId>\n\t\t\t\u003cversion>4.3.1\u003c/version>\n\t\t\u003c/dependency>\n\n\nDemoDataSourceConfig类中的代码全部注释掉了\n\n报错信息:\n\n\u003cimg width=\"1676\" height=\"610\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/8950b850-7e1f-493d-9515-ea5f9d91ea8e\" />\n","author":{"url":"https://github.com/AFatFox","@type":"Person","name":"AFatFox"},"datePublished":"2025-09-25T10:35:21Z","url":"https://github.com/APIJSON/APIJSON/issues/847"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cf870c1d-3f80-2f61-dffd-3b606e6e82bf
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA75E:361535:192C57:22A2D4:6AFCA9B3
html-safe-nonce8f43f3a73864f90f5cc3b0feb72fa1efb1f093b65b1e4b0db448f2fefdc1aa87
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzVFOjM2MTUzNToxOTJDNTc6MjJBMkQ0OjZBRkNBOUIzIiwidmlzaXRvcl9pZCI6Ijg4MjgxMzM4Mjc5MjM0NTQzODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4621f6603a1529e3903c507d374738e7a8c26d5f72d750fe1539de1300252466
hovercard-subject-tagissue:3453024261
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/APIJSON/APIJSON/847/issue_layout
twitter:imagehttps://opengraph.githubassets.com/41662ac6d05522a934a6c24c3d06c4693183a4d06d6de4119d93447f09ba8004/APIJSON/APIJSON/issues/847
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/41662ac6d05522a934a6c24c3d06c4693183a4d06d6de4119d93447f09ba8004/APIJSON/APIJSON/issues/847
og:image:altDescription 我在使用多数据源的情况下,尝试整合MyBatis-plus的多数据源的情况下出现了点问题,是这样的,我们项目中除了使用apijson外,也需要自己进行写一些增删改的接口,而且也要支持多数据源,所以这里我尝试整合MyBatis-plus的多数据源,我初步是整合成功了,通过apijson和自己写的接口,都可进行多数据源的增删改查,但是出现了一些问题,当项目使用一段时间,控...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAFatFox
hostnamegithub.com
expected-hostnamegithub.com
Nonee3084aead77cbcb4f4904fba53851fa1a0546b0dec3619bd250815e72588dc6d
turbo-cache-controlno-preview
go-importgithub.com/APIJSON/APIJSON git https://github.com/APIJSON/APIJSON.git
octolytics-dimension-user_id41146037
octolytics-dimension-user_loginAPIJSON
octolytics-dimension-repository_id74359442
octolytics-dimension-repository_nwoAPIJSON/APIJSON
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id74359442
octolytics-dimension-repository_network_root_nwoAPIJSON/APIJSON
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5410e4bebd3e45b138c853ecef3992279d86d5af
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/APIJSON/APIJSON/issues/847#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAPIJSON%2FAPIJSON%2Fissues%2F847
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAPIJSON%2FAPIJSON%2Fissues%2F847
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=APIJSON%2FAPIJSON
Reloadhttps://github.com/APIJSON/APIJSON/issues/847
Reloadhttps://github.com/APIJSON/APIJSON/issues/847
Reloadhttps://github.com/APIJSON/APIJSON/issues/847
APIJSONhttps://github.com/APIJSON
APIJSONhttps://github.com/APIJSON/APIJSON
Codehttps://github.com/APIJSON/APIJSON
Issues237 (237)https://github.com/APIJSON/APIJSON/issues
Pull requestshttps://github.com/APIJSON/APIJSON/pulls
Actionshttps://github.com/APIJSON/APIJSON/actions
Wikihttps://github.com/APIJSON/APIJSON/wiki
Security and qualityhttps://github.com/APIJSON/APIJSON/security
Insightshttps://github.com/APIJSON/APIJSON/insights
https://github.com/APIJSON/APIJSON
New issuehttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/847
New issuehttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/847
[xxx] 整合MyBatis-plus的dynamic多数据源发生Too many connectionshttps://github.com/APIJSON/APIJSON/issues/847#top
https://github.com/AFatFox
AFatFoxhttps://github.com/AFatFox
on Sep 25, 2025https://github.com/APIJSON/APIJSON/issues/847#issue-3453024261
@beanhttps://github.com/bean
@OverRidehttps://github.com/OverRide
https://private-user-images.githubusercontent.com/85828718/493854586-8950b850-7e1f-493d-9515-ea5f9d91ea8e.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTQ5NDM3MTIsIm5iZiI6MTc5NDk0MzQxMiwicGF0aCI6Ii84NTgyODcxOC80OTM4NTQ1ODYtODk1MGI4NTAtN2UxZi00OTNkLTk1MTUtZWE1ZjlkOTFlYThlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTE3VDE5MjMzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxODdiY2NjMmQ1YjE2Y2ZmOTQwZTk5YWFkOWVmNTE2NWNiZDIwZTZjY2Y3MTcwZThjOWQwOGRjMzZkMjMwNDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.4lfdc_sp--qzK3QCNz6iAZrMjoxQyvcnmD7YhfLUB_c
https://github.com/AFatFox
AFatFoxhttps://github.com/AFatFox
on Sep 28, 2025https://github.com/APIJSON/APIJSON/issues/847#issuecomment-3343672415
https://private-user-images.githubusercontent.com/85828718/494873592-c77ab68d-d702-441f-b2af-602b9bcbc084.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTQ5NDM3MTIsIm5iZiI6MTc5NDk0MzQxMiwicGF0aCI6Ii84NTgyODcxOC80OTQ4NzM1OTItYzc3YWI2OGQtZDcwMi00NDFmLWIyYWYtNjAyYjliY2JjMDg0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTE3VDE5MjMzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk4NGIyYzQyMjk3YzQwYWMyMDg4MzRmNDlmN2YzNDk0MjRiNDJjNGVmYWU2OWRhZGRiMTRmNTMwY2Y0ODE3NWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.tYMNVp6h-77iGqcpZ0pO-RyenS15kuMXv2cVmXZScRg
@OverRidehttps://github.com/OverRide
https://github.com/TommyLemon
TommyLemonhttps://github.com/TommyLemon
on Oct 2, 2025https://github.com/APIJSON/APIJSON/issues/847#issuecomment-3360918954
@AFatFoxhttps://github.com/AFatFox
https://github.com/Xuxin19960702
Xuxin19960702https://github.com/Xuxin19960702
on Jan 4, 2026https://github.com/APIJSON/APIJSON/issues/847#issuecomment-3708052532
@TommyLemonhttps://github.com/TommyLemon
https://github.com/TommyLemon
TommyLemonhttps://github.com/TommyLemon
on Jan 25, 2026https://github.com/APIJSON/APIJSON/issues/847#issuecomment-3796737508
@TommyLemonhttps://github.com/TommyLemon
@Xuxin19960702https://github.com/Xuxin19960702
Sign up for freehttps://github.com/signup?return_to=https://github.com/APIJSON/APIJSON/issues/847
Sign in to commenthttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/847
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.