oracle set newpage,springboot配置HANA和Oracle多数据源及PageHelper

配置数据库信息

因为要用到Druid读取配置,所以将druid提到了first后面

spring:

datasource:

first:

druid:

type: com.alibaba.druid.pool.DruidDataSource

driver-class-name: com.sap.db.jdbc.Driver

url: jdbc:sap://

username:

password:

initialSize: 5

minIdle: 5

maxActive: 20

# 配置获取连接等待超时的时间

maxWait: 60000

# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒

timeBetweenEvictionRunsMillis: 60000

# 配置一个连接在池中最小生存的时间,单位是毫秒

minEvictableIdleTimeMillis: 300000

validationQuery: SELECT 1 FROM DUMMY

testWhileIdle: true

testOnBorrow: false

testOnReturn: false

# 打开PSCache,并且指定每个连接上PSCache的大小

poolPreparedStatements: true

maxPoolPreparedStatementPerConnectionSize: 20

# 通过connectProperties属性来打开mergeSql功能;慢SQL记录

connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000

second:

druid:

type: com.alibaba.druid.pool.DruidDataSource

url: jdbc:oracle:

username:

password:

initialSize: 5

minIdle: 5

maxActive: 20

# 配置获取连接等待超时的时间

maxWait: 60000

# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒

timeBetweenEvictionRunsMillis: 60000

# 配置一个连接在池中最小生存的时间,单位是毫秒

minEvictableIdleTimeMillis: 300000

validationQuery: SELECT 1 FROM DUAL

testWhileIdle: true

testOnBorrow: false

testOnReturn: false

# 打开PSCache,并且指定每个连接上PSCache的大小

poolPreparedStatements: true

maxPoolPreparedStatementPerConnectionSize: 20

# 通过connectProperties属性来打开mergeSql功能;慢SQL记录

connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000

写两个Dataconfig文件,通过MapperScan扫描来指定那些用哪个数据源

@Configuration

@MapperScan(basePackages = {"com.xxxx.xx.xx.xxxx"},sqlSessionFactoryRef = "SqlSessionFactory1")

public class DataSource1Config {

@Bean(name = "Properties1")

@ConfigurationProperties(prefix = "spring.datasource.first")

public Properties Properties1(){

return new Properties();

}

/*

* 创建数据源datasource

* */

@Bean(name = "DataSource1")

@Primary

public DruidDataSource masterDataSource(@Qualifier("Properties1")Properties properties) {

DruidDataSource druidDataSource = new DruidDataSource();

druidDataSource.configFromPropety(properties);

try {

druidDataSource.init();

} catch (SQLException e) {

e.printStackTrace();

}

return druidDataSource;

}

/**

* 创建sqlsessionfactory

*/

@Bean(name = {"SqlSessionFactory1"})

@Primary

public SqlSessionFactory Hana1SqlSessionFactory(@Qualifier("DataSource1") DruidDataSource druidDataSource) throws Exception {

final SqlSessionFactoryBean sessionFactoryBean=new SqlSessionFactoryBean();

sessionFactoryBean.setDataSource(druidDataSource);

//分页插件

Interceptor interceptor = new PageInterceptor();

Properties properties = new Properties();

properties.setProperty("helperDialect", "hsqldb");

properties.setProperty("offsetAsPageNum", "true");

properties.setProperty("rowBoundsWithCount", "true");

properties.setProperty("reasonable", "true");

properties.setProperty("supportMethodsArguments","true");

properties.setProperty("params","pageNum=pageNum;pageSize=pageSize;");

interceptor.setProperties(properties);

sessionFactoryBean.setPlugins(new Interceptor[] {interceptor});

return sessionFactoryBean.getObject();

}

/*

* 创建事务DataSourceTransactionManager

* */

@Bean(name = {"TransactionManager1"})

@Primary

public DataSourceTransactionManager Hana1TransactionManager(){

return new DataSourceTransactionManager(masterDataSource(Properties1()));

}

@Bean(name = {"SqlSessionTemplate1"})

@Primary

public SqlSessionTemplate Hana1SqlSessionTemplate(@Qualifier("SqlSessionFactory1") SqlSessionFactory sqlSessionFactory){

return new SqlSessionTemplate(sqlSessionFactory);

}

}

第二个dataconfig也是一样写,就不重复上代码了。

最后需要注意在module的pom文件下加上依赖并将druid.jar放到resource下

com.alibaba

druid

1.1.19

system

${project.basedir}/src/main/resources/lib/druid-1.1.19.jar

下面这是我的jar目录

f2f16bf46496

druid.jar

如果报如下错就是上面的jar和pom没有配好,会在druidDatasource.init();的时候报错。

java.sql.SQLException: unknown jdbc driver : jdbc:sap://xx.xx.xx

另外我没有把依赖都写上,也很简单,我懒得写了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值