BeeCP-Starter是小蜜蜂连接池在Springboot上的启动器
1:文件方式配置数据源信息
2:支持多数据源配置
3:可通过自定义的方式支持其他数据源
4:支持配置Jndi数据源引入配置
1:Java版本:JDK1.8
2:Springboot版本:2.0.9.RELEASE
3:BeeCP版本:2.4.7
<dependency> <groupId>com.github.chris2018998</groupId> <artifactId>spring-boot-starter-beecp</artifactId> <version>1.3.1.RELEASE</version> </dependency>
application.properties
#单数据源配置点(ioc注册名:beeDataSource) spring.datasource.type=cn.beecp.BeeDataSource spring.datasource.poolName=BeeCP1 spring.datasource.username=root spring.datasource.password= spring.datasource.jdbcUrl=jdbc:mysql://localhost:3306/test spring.datasource.driverClassName=com.mysql.jdbc.Driver
application.properties
#多数据源配置起点(ioc注册名分别是d1,d2,d3) spring.datasource.nameList=d1,d2,d3 #第1数据源 spring.datasource.d1.primary=true spring.datasource.d1.poolName=BeeCP1 spring.datasource.d1.username=root spring.datasource.d1.password=root spring.datasource.d1.jdbcUrl=jdbc:mysql://localhost:3306/test spring.datasource.d1.driverClassName=com.mysql.cj.jdbc.Driver #第2数据源 spring.datasource.d2.jndiName=testDB #第3数据源 spring.datasource.d3.poolName=testDB spring.datasource.d3.datasourceType=com.xxx.xxxDataSource spring.datasource.d3.datasourceAttributeSetFactory=xxxx spring.datasource.d3.username=root spring.datasource.d3.password=root spring.datasource.d3.jdbcUrl=jdbc:mysql://localhost:3306/test spring.datasource.d3.driverClassName=com.mysql.cj.jdbc.Driver #xxxx为对应连接池的属性注入工厂类的实现,请参照*扩展接口*
DemoApplication.java
//引入多数据源标签 @EnableMultiDataSource @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
public interface DataSourceAttributeSetFactory { //get Properties value from environment and set to dataSource public void set(DataSource ds,String configPrefix,Environment environment)throws Exception; }