之前看到有人需要用spring boot连接Oracle数据库,其实很简单,只需要配置相应的配置文件即可,这里以阿里的druid为例进行配置
spring:
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
jdbc-url: jdbc:oracle:thin:@localhost:1521:tact5
username: uop_act5
password: password
#数据源类型
type: com.alibaba.druid.pool.DruidDataSource
#jdbc:oracle:thin:@10.124.0.42:1521:tact5 其中tact5为数据库的实例名称可连接数据库之后通过在pl/sql中执行select INSTANCE_NAME from v$instance查询
#springboot2以后自动配置需要使用driver-class-name和jdbc-url不然会报错
# 数据源其他配置
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
webservices:
path: com.sh.service.UserService