Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizable timeout on MyBatis

Is there any way to do a customizable timeout for MyBatis configuration?

I am using MyBatis with Spring framework, but I cannot make the 'defaultStatementTimeout' property customizable, as PropertyPlaceHolder on Spring.

like image 564
rvillablanca Avatar asked Aug 26 '26 15:08

rvillablanca


1 Answers

There is a way, but only through of the MyBatis configuration file. You can add the location of MyBatis configuration file in your Spring configuration file (there is a example in the MyBatis page) for load the settings that you want:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="location" value="classpath:mybatis-config.xml" />
</bean>

The MyBatis configuration file can be:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="defaultStatementTimeout" value="10"/> <!-- seconds -->
    </settings>
</configuration>
like image 79
Paul Vargas Avatar answered Aug 28 '26 04:08

Paul Vargas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!