Commit 8f321041 authored by data爬虫-冯 军凯's avatar data爬虫-冯 军凯

数据库初始化

parent 0652b808
......@@ -41,14 +41,14 @@ public class BlackListSourceConfig {
@Bean(name = "dataSource")
public DataSource blackListDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(blackListProperties.getJdbcUrl());
config.setPassword(blackListProperties.getPassword());
config.setJdbcUrl(blackListProperties.getJdbcUrl());
config.setUsername(blackListProperties.getUsername());
config.setMaximumPoolSize(blackListProperties.getMaxPoolSize());
config.setMinimumIdle(blackListProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("prepStmtCacheSize", "250");
return new HikariDataSource(config);
}
......
package cn.quantgroup.qgblservice.config.master;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* 原先黑名单库
*
* @Author fengjunkai
* @Date 2019-07-02 11:58
*/
@Data
@Configuration
public class MasterProperties {
@Value("${master.db.driver}")
private String driverClass;
@Value("${master.db.minPoolSize}")
private int minPoolSize;
@Value("${master.db.maxPoolSize}")
private int maxPoolSize;
@Value("${master.db.url}")
private String jdbcUrl;
@Value("${master.db.username}")
private String username;
@Value("${master.db.password}")
private String password;
}
package cn.quantgroup.qgblservice.config.master;
import cn.quantgroup.qgblservice.config.blacklist.BlackListProperties;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* @Author fengjunkai
* @Date 2019-07-02 11:58
*/
@Import({MasterProperties.class})
@MapperScan(basePackages = MasterSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
@Configuration
public class MasterSourceConfig {
static final String PACKAGE = "cn.quantgroup.qgblservice.repository.mybatis.mapper.master";
@Value("${master.mapper-locations}")
private String mapperLocations;
@Value("${master.type-aliases-package}")
private String typeAliasesPackage;
@Value("${master.config-location}")
private String configLocation;
@Autowired
private MasterProperties masterProperties;
@Bean(name = "dataSource")
public DataSource masterDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(masterProperties.getJdbcUrl());
config.setPassword(masterProperties.getPassword());
config.setMaximumPoolSize(masterProperties.getMaxPoolSize());
config.setUsername(masterProperties.getUsername());
config.setMinimumIdle(masterProperties.getMinPoolSize());
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "masterSqlSessionFactory")
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation));
return sessionFactory.getObject();
}
@Bean(name = "masterSqlSessionTemplate")
public SqlSessionTemplate masterSqlSessionTemplate(@Qualifier("masterSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.master;
/**
* @Author fengjunkai
* @Date 2019-07-02 14:50
*/
public class test {
}
package cn.quantgroup.qgblservice.repository.mybatis.mapper.master;
/**
* @Author fengjunkai
* @Date 2019-07-02 14:50
*/
public interface TestMapper {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.quantgroup.qgblservice.repository.mybatis.mapper.master.TestMapper">
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment