mysql配置参数datasource_Springboot配置2种数据源
(Oracle,。。。
基础配置
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.urname=root
spring.datasource.password=best
#数据源类型:c3p0
hange.v2.c3p0.ComboPooledDataSource
MySQL
#Springboot整合的MySQL
spring.datasource.sql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springbatch
spring.datasource.urname=root
spring.datasource.password=root
#数据源类型:c3p0
hange.v2.c3p0.ComboPooledDataSource
整合c3p0
⾃定义配置类
@Configuration //声明为配置类
public class DataSourceConfiguration {
@Bean(name = "dataSource") //对象及名称
@Primary //主要的候选者
//配置属性,prefix : 前缀 spring.datasource固定
@ConfigurationProperties(prefix = "spring.datasource.c3p0")
public DataSource createDataSource(){
ate() // 创建数据源构建对象
.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.ur = 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.sql.jdbc.Driver
spring.datasource.c3p0.jdbcUrl=jdbc:mysql://localhost:3306/springbatch spring.datasource.c3p0.ur=root
spring.datasource.c3p0.password=root
spring.datasource.c3p0.maxPoolSize=30
spring.datasource.c3p0.minPoolSize=10
spring.datasource.c3p0.initialPoolSize=10
需要注意的是:
URL必须写对,不然报各种奇怪的错误.如:
拒绝连接
⽹络适配器不对
等等!