[英]Configure HikariCp dataSource with HikariConfig in mybatis in xml mapper configuration
I am trying to configure HikariCp in mybatis using xml configuration我正在尝试使用 xml 配置在 mybatis 中配置 HikariCp
I want to know hoe to set the hikariCongig object in object in the mapper configuration.我想知道如何在映射器配置中的 object 中设置 hikariCongig object。
my config looks like this:我的配置如下所示:
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="com.xyz.config.HikariCPDataSourceFactory" >
<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/beta-prod-db" />
<property name="username" value="postgres" />
<property name="password" value="${password}" />
<property name="poolName" value="test"/>
<property name="maxPoolSize" value="20" />
<property name="registerMbeans" value="true"/>
<property name="minimumIdle" value="5"/>
</dataSource>
</environment>
HikariCPDataSourceFactory.java HikariCPDataSourceFactory.java
public class HikariCPDataSourceFactory extends PooledDataSourceFactory {
public HikariCPDataSourceFactory() {
//HikariConfig hikariConfig = new HikariConfig();
this.dataSource = new HikariDataSource();
}
}
i dont find any online article hat shows how to set the hikariConfig object in hikarIDataSource object through xml configuration.我没有找到任何在线文章帽子显示如何通过 xml 配置在 hikarIDataSource object 中设置 hikariConfig object。
using Spring i can crearte a bean for hikariConfig and pass it as a parameter in hikariDataSource object, but here i am not using spring so need to find a way with xml. using Spring i can crearte a bean for hikariConfig and pass it as a parameter in hikariDataSource object, but here i am not using spring so need to find a way with xml.
Without hikariConfig object if i try to get the HikariPoolMXBean object from datSource i get the exception org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
Without hikariConfig object if i try to get the HikariPoolMXBean object from datSource i get the exception org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
HikariCP 1.4.0 MBean InstanceNotFoundException HikariCP 1.4.0 MBean InstanceNotFoundException
this article says it only works when i set the hikariConfig Object本文说它仅在我设置 hikariConfig Object 时才有效
i couldnt find a way to configure the hikariConfig in xml Here is the workaround i used that works well for me.我找不到在 xml 中配置 hikariConfig 的方法这是我使用的对我很有效的解决方法。
HikariDataSource hikariDataSource = null;
HikariConfig hikariConfig = new HikariConfig();
dataSource.copyStateTo(hikariConfig);
hikariDataSource = new HikariDataSource(hikariConfig);
once i get the dataSource object i copy the state to a hikariConfig object and create new dataSource object using it.一旦我得到数据源 object,我将 state 复制到 hikariConfig object 并使用它创建新的数据源 ZA8CFDE6331BD59EB26ACZF84。 Also we can make it singleton so only one instance is created.我们也可以将其设为 singleton,因此只创建一个实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.