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

690阅读 0评论2022-05-26 fhadmin
分类:Java


点击(此处)折叠或打开


  1. 1. pom 

  2.         <!-- 达梦数据库驱动 -->
  3.         <dependency>
  4.          <groupId>com.dm</groupId>
  5.          <artifactId>DmJdbcDriver18</artifactId>
  6.          <version>1.8</version>
  7.         </dependency>

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

  9. 2. druid 配置 application.properties

  10. #数据源1
  11. datasource.no1.driver-class-name: dm.jdbc.driver.DmDriver
  12. datasource.no1.url=jdbc:dm://192.168.0.11:5238/SYSDBA?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8
  13. datasource.no1.username=SYSDBA
  14. datasource.no1.password=root123456789
  15. 3. 配置类

  16. package org.fh.config;
  17.  
  18. import java.sql.SQLException;
  19.  
  20. import javax.sql.DataSource;
  21.  
  22. import org.apache.ibatis.session.SqlSessionFactory;
  23. import org.mybatis.spring.SqlSessionFactoryBean;
  24. import org.mybatis.spring.annotation.MapperScan;
  25. import org.springframework.beans.factory.annotation.Qualifier;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.context.annotation.Bean;
  28. import org.springframework.context.annotation.Configuration;
  29. import org.springframework.context.annotation.Primary;
  30. import org.springframework.core.io.DefaultResourceLoader;
  31. import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
  32. import org.springframework.jdbc.datasource.DataSourceTransactionManager;
  33.  
  34. import com.alibaba.druid.pool.DruidDataSource;
  35.  
  36. /**
  37.  * 说明:第一数据源配置
  38.  * 作者:FH Admin
  39.  * from:fhadmin.cn
  40.  */
  41. @Configuration
  42. @MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory") //扫描 Mapper 接口并容器管理
  43. public class MasterDataSourceConfig {
  44.  
  45. ……
  46.  //其中的 dataSource.addFilters("wall"); 去掉,否则访问不了数据库
  47.     @Bean(name = "masterDataSource")
  48.     @Primary
  49.     public DataSource masterDataSource() throws SQLException {
  50.         DruidDataSource dataSource = new DruidDataSource();
  51.         dataSource.setDriverClassName(driverClass);
  52.         dataSource.setUrl(url);
  53.         dataSource.setUsername(user);
  54.         dataSource.setPassword(password);
  55.         dataSource.addFilters("stat");
  56.         //dataSource.addFilters("wall");
  57.         return dataSource;
  58.     }
  59.  
  60.  ……
  61. }



上一篇:java 生成 zip格式 压缩文件
下一篇:SpringBoot 2.7.0 处理跨域的问题