APIJSON icon indicating copy to clipboard operation
APIJSON copied to clipboard

SQLExecutor中getConnection始终为null

Open JerryWwang opened this issue 4 years ago • 4 comments

环境信息

  • 系统:
  • JDK:
  • 数据库:
  • APIJSON:

问题描述

DemoApplication.getApplicationContext().getBean(DataSource.class); 始终显示 DemoSQLExecutor.ERROR: DemoSQLExecutor.getConnection try { DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); ..} catch (Exception e) = No qualifying bean of type 'javax.sql.DataSource' available

ApplicationContext始终获取不到bean实例 找了相关资料还是没有研究出所以然,想请您麻烦讲一下这里如何修改能使用连接池

image

JerryWwang avatar Apr 08 '21 01:04 JerryWwang

你都没配置连接池当然拿不到,谷歌或百度搜 "SpringBoot 连接池"

TommyLemon avatar Apr 08 '21 02:04 TommyLemon

可是springboot启动时不是会自动创建连接池么,对不起,这里不是很了解,能麻烦您多说几句么

image

JerryWwang avatar Apr 09 '21 03:04 JerryWwang

这里是从 SpringBoot 中取 AOP 注入的连接池类。 image

你都没配置怎么会自动创建?按照具体 HikariCP/Druid 等连接池的官方要求去配置一份,APIJSON 本身不做任何要求或限制。

TommyLemon avatar Apr 20 '21 08:04 TommyLemon

新增数据源关键词 @datasource,可由业务完全自定义 https://github.com/Tencent/APIJSON/releases/tag/4.7.0

新增 连接池及多数据源 Demo(Druid + HikariCP) https://gitee.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server

TommyLemon avatar Jun 21 '21 03:06 TommyLemon