J'utilise le printemps jpa avec config par défaut et ressort-batis avec config personnalisé dans le même projet. Les requêtes Jpa sont toujours rapides, mais les requêtes ibatis sont parfois lentes. Quel pourrait être le problème. Ma config batis:Mises à jour lentes dans ibatis en utilisant avec le ressort jpa
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.beans.PropertyVetoException;
@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = {""}, sqlSessionFactoryRef = "mySqlSessionFactory")
public class DaoConfig {
@Value("${spring.datasource.url}")
private String databaseUrl;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName;
@Value("${mybatis.mapperLocations}")
private Resource[] mapperLocation;
@Value("${mybatis.typeAliasesPackage}")
private String typeAliasesPackage;
private DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(databaseUrl, username, password);
dataSource.setDriverClassName(driverClassName);
return dataSource;
}
private ManagedTransactionFactory dataSourceTransactionManager() throws PropertyVetoException {
return new ManagedTransactionFactory();
}
@Bean(name = "mySqlSessionFactory")
public SqlSessionFactory mySqlSessionFactory() throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setTransactionFactory(dataSourceTransactionManager());
sessionFactory.setMapperLocations(mapperLocation);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
return sessionFactory.getObject();
}
}
et la dépendance:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
Vos méthodes dataSource() et dataSourceTransactionManager() ne devraient-elles pas être annotées avec @Bean? Sans cela, chaque fois que vous appelez mySqlSessionFactory(), vous allez créer une nouvelle connexion. –
@MichaelPeacock pouvez-vous copier ce commentaire comme réponse. Je sens que tu as raison, je le vérifie. THX! – ipoteka