package com.lm.springboot_mybatis_oracle_cassandra.datasource;
import java.util.Calendar;
import javax.sql.DataSource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
/**
* aop事务控制
*
* @author liangming.deng
* @date 2017年6月9日
*
*/
@Aspect
@Configuration
public class TranscationAop {
private static Logger logger = LoggerFactory.getLogger(TranscationAop.class);
@Autowired
PlatformTransactionManager transactionManager;
/**
* 注入dataSource
*
* @param dataSource
* @return
*/
@Bean
public PlatformTransactionManager txManager(@Qualifier("primaryDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
/**
* 定义事务扫描包
*/
@Pointcut("execution(* com.lm.springboot_mybatis_oracle_cassandra.service..*.*(..))")
public void service() {
}
/**
* 环绕通知 事务
*
* @param pjp
* @return
*/
@Around("service()")
public Object tran(ProceedingJoinPoint pjp) {
long startTimeLong = Calendar.getInstance().getTimeInMillis();
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
String classInfo = getClassInfo(pjp);
try {
pjp.proceed();
} catch (Throwable throwable) {
logger.error(classInfo + " 异常 事务回滚 :" + throwable.getMessage());
transactionManager.rollback(transactionStatus);
return null;
}
transactionManager.commit(transactionStatus);
long endTimeLong = Calendar.getInstance().getTimeInMillis();
logger.info(classInfo + " 事务提交成功,耗时:" + (endTimeLong - startTimeLong));
return null;
}
/**
* 获取className和method
*
* @param pjp
* @return
*/
private static String getClassInfo(ProceedingJoinPoint pjp) {
StringBuilder sBuilder = new StringBuilder();
if (null == pjp) {
return sBuilder.toString();
}
sBuilder.append(pjp.getTarget().getClass().getSimpleName()).append(" ").append(pjp.getSignature().getName());
return sBuilder.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Springboot+Mybatis+Maven+Oracle+Cassandra+事务(Aop)+定时任务实现
共88个文件
java:11个
xml:9个
master:4个
4星 · 超过85%的资源 需积分: 33 158 下载量 175 浏览量
2017-06-09
12:37:50
上传
评论 1
收藏 80KB ZIP 举报
温馨提示
本文将通过示例介绍Springboot,mybatis,maven,oracle,cassandra,aop事务,定时任务等框架的集成,因此业务不会复杂,供学习使用。
资源推荐
资源详情
资源评论
收起资源包目录
springboot-mybatis-oracle-cassandra.zip (88个子文件)
springboot-mybatis-oracle-cassandra
.project 587B
src
test
java
com
lm
springboot_mybatis_oracle_cassandra
AppTest.java 708B
main
assembly
package.xml 2KB
resources
application.properties 1KB
logback-spring.xml 1KB
mybatis
mapper
UpsCalendarMapper.xml 2KB
mybatis-config.xml 576B
java
com
lm
springboot_mybatis_oracle_cassandra
service
UpsCalendarService.java 395B
impl
UpsCalendarServiceImpl.java 2KB
StartupApplication.java 543B
mapper
UpsCalendarMapper.java 529B
dao
UpsCalendarCassandraDao.java 326B
impl
UpsCalendarCassandraDaoImpl.java 944B
entity
UpsCalendarEntity.java 2KB
datasource
DataSourceConfig.java 2KB
TranscationAop.java 3KB
task
SyncTask.java 1018B
target
classes
application.properties 1KB
META-INF
MANIFEST.MF 3KB
maven
com.lm
springboot-mybatis-oracle-cassandra
pom.properties 309B
pom.xml 4KB
logback-spring.xml 1KB
mybatis
mapper
UpsCalendarMapper.xml 2KB
mybatis-config.xml 576B
test-classes
datasync.log 91KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 119B
.git
logs
HEAD 352B
refs
heads
master 352B
remotes
origin
master 141B
index 2KB
COMMIT_EDITMSG 12B
objects
pack
0a
3c94ce11afd2e2b27318cf48d442869cf406e2 44B
43
c008a038ba62513943b78efaf5a36e5ba39e3a 77B
c5
a367bb4011cd3cd8351cbdffabbdeee842dfc9 528B
8f
a1ff15178e752dfbb65554ec48054a33da9483 676B
67
23dcd051a464ccc4c7ce70b0db580ec1a55675 45B
0b8d5170fc56e20e4ffe3e8b87b8a75475840b 166B
26
f399d7dcb1c4241dda52d5dd7b1d39e38a0815 105B
df
67c6888675e03b4873883a415eba46ee090ad0 419B
62
ba700d2e0120a41abbd07f47659fc5d8595bb3 144B
info
9c
d63437cd586d939664af6458abbf927f9a22ff 1KB
a9
f9c83eec3e581319752750aec008622946086c 46B
99
ffd01c570d317741c13111efc10b8b3dedf6ff 515B
82
53621995f0fff9ff4babeb379a9bbaf818815e 743B
a8
7c03082a9bc5e9414186409e0ea687e3e1c9b4 757B
11
899e766243fd2c7a0e1b1a6e45893dfb076b69 257B
8b4a7c423e913fe53cb8f7279301b6996f91db 169B
2e
3317163b657306bbba61bcdc404c97bf29fb2f 81B
90
2b906d16e043b88dfbf045db077c5bd25d3354 824B
ae
d50a7092396ffe52deb9ebef2ee2f71d22ea0d 228B
5b
427cb62e03a0825386ecdcd613f8dd8621123a 67B
9f
c585f0353ce6db7c44ba398f57e03696bb8032 81B
d5
9388c452f9f46063738f9cb58f3d57ecb08169 112B
64
a92aa401ed0d3bc412a10a6458b0aef390647b 44B
dc
cd1be1e15f1ffe644e97698f2064bef17b9262 543B
32
437e08eba8de805e53709d0add0715a13772b9 1005B
f2
0249faae4b4a03a4a207881effb1cf05eab024 98B
3c
26fe7e2d2bb2c39d1193ac7cf238c34b88f34c 104B
fd
3daf84630360df9c1835cbf91e69fb3a4dae4e 77B
b7
eb1fa4a1df44a8764c99af924e79d9780c1b63 248B
601078affac39526955fcc99a0987d0b4b4e1d 57B
59
cae69ec276cca0bebddbf4801668e82630ef4f 143B
5f
77382dc6798acab72890e4edfbfad45209001a 77B
6b
19b77eb8e9e13fe0da8268d27a3f6a954e5824 270B
8c
496da1ffd75d6a8499b42f23c58f36ac89ffda 72B
e5
9549d1759a179e91903d37d825dd90ea87eadd 112B
4f
1303ed911f2666c53b90251aaf882a9fff9fd9 328B
e2
0b77c775d7c779c1a86838cd2d262d3ec89f00 47B
30
3870e60bf1c99366d171cca29f61af26cb7c13 644B
92
5e9e4dee1daf310f1c8d023abdef7697868ae5 74B
83
6556de14e88af05e5af3694080d150f20af9a3 57B
ad
b35973ef8969b6e23b0c2144a9cc24162bcf03 66B
56
097ffb97d75b9c5c7a958921ef1767cd8a7fc3 256B
7b
31bc982ca5ac7bd56b1d5b42164ad26d0431dc 75B
f6
76962b8f7b58f0a1f744308efd5454364a27f2 56B
ea
7900e56ab2c710a46d1e728b4b9db427b7576b 67B
c7
d7e57a131f81d35bec0cb50845725c71b61c80 501B
d2
4651e646c5856c31a8dd38a2e4ce2653eae495 95B
a9e6eff7933cac58fcd84755bf756f567b8c0d 321B
HEAD 23B
config 279B
refs
heads
master 41B
tags
remotes
origin
master 41B
branches
hooks
pom.xml 4KB
.classpath 1KB
.gitignore 60B
共 88 条
- 1
IT狗探求
- 粉丝: 420
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页