Closed 871765337 closed 2 months ago
sr版本:3.2.3 MySQL jdbc版本:8.0.29 springboot版本:3.2.3 问题描述:
连接代码:
import com.alibaba.druid.pool.DruidDataSource; import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @Configuration @Slf4j @MapperScan(basePackages = "com.xxx.dao.data", sqlSessionFactoryRef = "srSqlSessionFactory") public class SrDataSourceConfig { @Resource private MybatisPlusInterceptor mybatisPlusInterceptor; @Bean(name = "srDataSource") @ConfigurationProperties("spring.datasource.sr") public DruidDataSource srDataSource() { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setSocketTimeout(15 * 60 * 1000); return druidDataSource; } @Bean(name = "srSqlSessionFactory") public SqlSessionFactory sqlSessionFactory() throws Exception { MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean(); factoryBean.setDataSource(srDataSource()); factoryBean.setPlugins(mybatisPlusInterceptor); factoryBean.setTypeAliasesPackage("com.xxx.entity"); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factoryBean.setMapperLocations(resolver.getResources("classpath*:data_mapper/*.xml")); MybatisConfiguration mybatisConfiguration = new MybatisConfiguration(); mybatisConfiguration.setDefaultStatementTimeout(60 * 15); factoryBean.setConfiguration(mybatisConfiguration); return factoryBean.getObject(); } @Bean(name = "srDataSqlSessionTemplate") public SqlSessionTemplate testSqlSessionTemplate() throws Exception { return new SqlSessionTemplate(sqlSessionFactory()); } }
sql执行代码,多次执行指的是多次调用executeSelect方法
@Component @Slf4j public class SrSelector implements ISrSelector { @Resource(name = "srDataSource") private DruidDataSource dataSource; @Override public ResultSet executeSelect(String sql) throws SQLException { ResultSet rs = null; log.debug("执行SR 查询 {}", sql); try ( Connection connection = dataSource.getConnection(); PreparedStatement ps = connection.prepareStatement(sql)) { rs = ps.executeQuery(); return rs; } catch (SQLException e) { throw e; } }
升级到3.3之后暂时没有遇到该问题
sr版本:3.2.3 MySQL jdbc版本:8.0.29 springboot版本:3.2.3 问题描述:
连接代码:
sql执行代码,多次执行指的是多次调用executeSelect方法