首页>代码>spring boot调用mysql存储过程,mysql存储过程分页 调用存储过程分页>/springboot-procedure/src/main/java/com/simon/springbootprocedure/DataSourceConfig.java
package com.simon.springbootprocedure; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 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; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; /** * @author Simon */ @Configuration @MapperScan(basePackages = "com.simon.springbootprocedure", sqlSessionFactoryRef = "DBDataSqlSessionFactory") public class DataSourceConfig { @Bean(name = "DBDataSource") @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "DBDataSqlSessionFactory") public SqlSessionFactory sqlSessionFactory(@Qualifier("DBDataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/dbMapper.xml")); return bean.getObject(); } @Bean(name = "DBDataTransactionManager") public DataSourceTransactionManager transactionManager(@Qualifier("DBDataSource") DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } @Bean(name = "DBDataSqlSessionTemplate") public SqlSessionTemplate sqlSessionTemplate( @Qualifier("DBDataSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); } }
最近浏览更多
mengmeng12323423 LV3
2023年6月17日
zhonghua123 LV2
2023年6月13日
1529860026 LV24
2023年6月1日
syczzxj LV9
2023年5月30日
lingtiejing LV15
2023年5月13日
小帅哥 LV2
2023年5月7日
Rd_s20192753
2023年5月2日
暂无贡献等级
3263394665 LV9
2023年4月18日
ssh123 LV10
2023年4月18日
youzitao LV11
2023年4月16日