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个
4星 · 超过85%的资源 需积分: 34 128 下载量 183 浏览量
2017-08-11
17:58:11
上传
评论
收藏 19KB RAR 举报
温馨提示
搞了一下午 见识到了springboot和druid的好用之处 监控太好用搞了一下午 见识到了springboot和druid的好用之处 监控太好用
资源推荐
资源详情
资源评论
收起资源包目录
springboot .rar (29个子文件)
springboot - 副本
src
main
resources
application.properties 2KB
java
com
entity
User.java 961B
controller
UserController.java 826B
mybatis
MybatisConfig.java 2KB
druid
DruidDataSourceConfig.java 776B
DruidStatFilter.java 420B
DruidStatViewServlet.java 845B
service
UserServiceImpl.java 479B
UserService.java 131B
mapper
UserMapper.java 415B
MySpringBootApplication.java 400B
webapp
druid
index.html 131B
test
resources
java
.classpath 1KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 191B
org.eclipse.jdt.core.prefs 243B
pom.xml 2KB
target
classes
com
entity
User.class 2KB
controller
UserController.class 1KB
mybatis
MybatisConfig.class 3KB
druid
DruidDataSourceConfig.class 996B
DruidStatFilter.class 618B
DruidStatViewServlet.class 717B
MySpringBootApplication.class 768B
service
UserService.class 185B
UserServiceImpl.class 772B
mapper
UserMapper.class 481B
application.properties 2KB
test-classes
.project 562B
共 29 条
- 1
资源评论
- oLeiChang2018-07-14还行可以用。
- 山城棒棒军军长2017-11-27可以使用,初学者合适
- chen_xyun2018-07-06可以使用还不错谢谢
曲终--人散
- 粉丝: 6
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- springmvc的使用教程,包含详细的代码
- Python毕业设计-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集.zip
- jdk11,64位windows.直接安装
- ssm相关使用教程及maven web 使用步骤
- 【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍.zip
- IntelliJ IDEA 2023.2.3,无需解压,直接安装
- 使用纯粹的PHP 编写的 kafka 客户端kafka-php-master.zip
- PS插件Photoshop-LayersToPNG-JH-v1.5.1.jsx
- 基于STM32单片机心率脉搏监测健康运动计步系统源码带视频演示.7z
- mmexport1713192608513.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功