package com.mybatis;
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.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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 org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Created by huguoju on 2017/1/4.
*/
@Configuration
@EnableTransactionManagement
@ComponentScan
@MapperScan("com.mapper")
public class MybatisConfig {
@Value("${spring.datasource.type}")
private Class<? extends DataSource> dataSourceType;
@Bean(name="dataSource", destroyMethod = "close", initMethod="init")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().type(dataSourceType).build();
}
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource());
sqlSessionFactoryBean.setTypeAliasesPackage("com.entity");
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:com/mapper/*.xml"));
sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
return sqlSessionFactoryBean.getObject();
}
/**
* 配置事务管理器
*/
@Bean(name = "transactionManager")
@Primary
public DataSourceTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) throws Exception {
return new DataSourceTransactionManager(dataSource);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
springboot+mybatis+druid整合 包括druid监控配置

共29个文件
java:10个
class:10个
prefs:3个


温馨提示
搞了一下午 见识到了springboot和druid的好用之处 监控太好用搞了一下午 见识到了springboot和druid的好用之处 监控太好用
资源推荐
资源详情
资源评论























收起资源包目录


























































共 29 条
- 1
资源评论

- oLeiChang2018-07-14还行可以用。
- 山城棒棒军军长2017-11-27可以使用,初学者合适
- chen_xyun2018-07-06可以使用还不错谢谢

曲终--人散
- 粉丝: 23
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 互联网对钢琴教学的影响(1).docx
- 浅议大数据互联网+政务服务模式的创新发展(1).docx
- 电气控制与PLC基本控制电路(2)(1).ppt
- 关于医院档案信息化管理的研究(1).docx
- 动物营养学网络开放课网站大学论文(1).doc
- 常用聊天传输工具下载软件的协议及端口(1).doc
- 基于JSP的在线考试系统设计与实现(1).doc
- 探究人工智能发展的伦理困境(1).docx
- 会计实务:计算机记账的基本要求(1).doc
- 《C语言程序设计教程》课后题答案(1).doc
- 支票打印软件项目节能评估报告模板(1).docx
- 浅析互联网金融发展过程中的法制建设问题与对策分析(1).docx
- 熔化和凝固+flash课件-修改自用(1).ppt
- 联通大数据业务实践及能力介绍(1).ppt
- 信息化教学在中职数学教学中的应用(1).docx
- 软件工程实验心得体会范文(1).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
