• 欢迎光临~

springboot 整合国产达梦数据库配置代码

开发技术 开发技术 2022-05-26 次浏览

1. pom 

		<!-- 达梦数据库驱动 -->
		<dependency>
		    <groupId>com.dm</groupId>
		    <artifactId>DmJdbcDriver18</artifactId>
		    <version>1.8</version>
		</dependency>

maven 中央仓库里面没有,需要手动安装到 maven 本地仓库

2. druid 配置 application.properties

#数据源1
datasource.no1.driver-class-name: dm.jdbc.driver.DmDriver
datasource.no1.url=jdbc:dm://192.168.0.11:5238/SYSDBA?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8
datasource.no1.username=SYSDBA
datasource.no1.password=root123456789

3. 配置类

package org.fh.config;
 
import java.sql.SQLException;
 
import javax.sql.DataSource;
 
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
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.Primary;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 
import com.alibaba.druid.pool.DruidDataSource;
 
/**
 * 说明:第一数据源配置
 * 作者:FH Admin
 * from:fhadmin.cn
 */
@Configuration
@MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory") //扫描 Mapper 接口并容器管理
public class MasterDataSourceConfig {
 
……
 //其中的 dataSource.addFilters("wall"); 去掉,否则访问不了数据库
    @Bean(name = "masterDataSource")
    @Primary
    public DataSource masterDataSource() throws SQLException {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
        dataSource.addFilters("stat");
        //dataSource.addFilters("wall");
        return dataSource;
    }
 
 ……
}

 

程序员灯塔
转载请注明原文链接:springboot 整合国产达梦数据库配置代码
喜欢 (0)