基础配置
Oracle
#springboot内置oracle jdbc参数
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@172.117.145.113:1521:oratest
spring.datasource.username=root
spring.datasource.password=best
#数据源类型:c3p0
spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
MySQL
#Springboot整合的MySQL spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/springbatch spring.datasource.username=root spring.datasource.password=root #数据源类型:c3p0 spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
整合c3p0
自定义配置类
@Configuration //声明为配置类 public class DataSourceConfiguration { @Bean(name = "dataSource") //对象及名称 @Primary //主要的候选者 //配置属性,prefix : 前缀 spring.datasource固定 @ConfigurationProperties(prefix = "spring.datasource.c3p0") public DataSource createDataSource(){ return DataSourceBuilder.create() // 创建数据源构建对象 .type(ComboPooledDataSource.class) // 设置数据源类型 .build(); // 构建数据源对象 } }
Oracle
#Springboot整合c3p0,定义配置参数 spring.datasource.c3p0.jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl spring.datasource.c3p0.driverClass = oracle.jdbc.driver.OracleDriver spring.datasource.c3p0.user = rootw spring.datasource.c3p0.password = best spring.datasource.c3p0.maxPoolSize=10 spring.datasource.c3p0.minPoolSize=5 spring.datasource.c3p0.initialPoolSize=5
MySQL
#整合c3p0,要自定义配置类 spring.datasource.c3p0.driverClass=com.mysql.jdbc.Driver spring.datasource.c3p0.jdbcUrl=jdbc:mysql://localhost:3306/springbatch spring.datasource.c3p0.user=root spring.datasource.c3p0.password=root spring.datasource.c3p0.maxPoolSize=30 spring.datasource.c3p0.minPoolSize=10 spring.datasource.c3p0.initialPoolSize=10
需要注意的是:
URL必须写对,不然报各种奇怪的错误.如:
拒绝连接
网络适配器不对
等等!