点击(此处)折叠或打开
-
-
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;
-
}
-
-
……
-
}
-
-