码迷,mamicode.com
首页 > 数据库 > 详细

springboot 双 sqlite 数据源配置

时间:2019-12-26 19:18:02      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:collectd   import   turn   factory   pool   vat   repo   ext   数据   

1.在配置资源文件中 配置如下

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
 #SQLLITE
	
#SQLLITE
spring.datasource.sqlite.driver-class-name=org.sqlite.JDBC
spring.datasource.sqlite.url=jdbc:sqlite:db/personInfo.db
	
#SQLLITE
spring.datasource.sqlite2.driver-class-name=org.sqlite.JDBC
spring.datasource.sqlite2.url=jdbc:sqlite:db/bug.db

  2.创建配置类

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class BugcollectConfig {	
	@Bean(name = "sqliteDataSource")
	@Primary
    @Qualifier("sqliteDataSource")
    @ConfigurationProperties(prefix="spring.datasource.sqlite")
	public DataSource sqliteDataSource() {
        return DataSourceBuilder.create().build();
    }
	
	@Bean(name = "sqliteDataSource2")	
    @Qualifier("sqliteDataSource2")
    @ConfigurationProperties(prefix="spring.datasource.sqlite2")
	public DataSource sqliteDataSource2() {
        return DataSourceBuilder.create().build();
    }
	
	@Bean(name = "sqliteJdbcTemplate")
    public JdbcTemplate sqliteJdbcTemplate(@Qualifier("sqliteDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
	
	@Bean(name = "sqliteJdbcTemplate2")
    public JdbcTemplate sqliteJdbcTemplate2(@Qualifier("sqliteDataSource2") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}

  3.dao层实现类中配置

@Repository
public class BugcollectDaoImp implements BugcollectDao {
	protected UUIDHexGenerator uuid = UUIDHexGenerator.getInstance();
	@Autowired
	@Qualifier("sqliteJdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	@Qualifier("sqliteJdbcTemplate2")
	private JdbcTemplate jdbcTemplate2;

	
	

  

springboot 双 sqlite 数据源配置

标签:collectd   import   turn   factory   pool   vat   repo   ext   数据   

原文地址:https://www.cnblogs.com/liuna369-4369/p/12103790.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!