赞
踩
1:新增达梦数据库配置类
package com.hrkj.coll.config; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; @Configuration public class DMConfiguration { @Bean(name = "dmDataSource") @Primary @ConfigurationProperties(prefix="spring.datasource.hikari") public DataSource dmDataSource() { return DataSourceBuilder.create().build(); } /** * 创建sqlSessionFactory * @param dataSource * @return * @throws Exception */ @Bean(name = "dmSqlSessionFactory") public SqlSessionFactory dmSqlSessionFactory(@Qualifier("dmDataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); sqlSessionFactoryBean.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/*.xml")); return sqlSessionFactoryBean.getObject(); } /** * 创建事务管理器 * @param dataSource * @return */ @Bean(name = "dmTransactionManager") public DataSourceTransactionManager dmTransactionManager(@Qualifier("dmDataSource") DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } /** * 创建sqlSession模板 * @param sqlSessionFactory * @return */ @Bean(name = "dmSqlSessionTemplate") public SqlSessionTemplate dmSqlSessionTemplate(@Qualifier("dmSqlSessionFactory") SqlSessionFactory sqlSessionFactory) { return new SqlSessionTemplate(sqlSessionFactory); } }
2:application.properties文件中配置达梦数据库连接
spring.datasource.hikari.jdbc-url=jdbc:dm://ip地址:端口号/DMSJK
spring.datasource.hikari.username=用户名
spring.datasource.hikari.password=密码
3:注意事项
//重写sqlSessionFactory时,sql映射文件会失效 需要手动指定
PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/*.xml"));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。