springboot 1.5.6版本集成druid mybatis后事务不回滚

最新学习spring boot 使用druid mybatis集成 druid使用的阿里巴巴的spring-boot-druid-starter集成后,程序执行异常后未进行回滚。
application.yml配置如下:
#spring配置
spring:
http:
encoding:
force: true
charset: UTF-8
multipart:
enabled: true
max-file-size: 1024MB
#数据库连接配置
datasource:
druid:
name: datasource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/iwant?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
default-auto-commit: true
#初始化大小
initial-size: 5
max-active: 20
# 配置获取连接等待超时的时间
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 30000
#检测连接是否有效的sql
validation-query: SELECT 'x'
validation-query-timeout: 60000
test-while-idle: true
test-on-borrow: false
test-on-return: false
# 打开PSCache,并且指定每个连接上PSCache的大小 Mysql下建议关闭
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 1
#max-open-prepared-statements: 1

# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j2
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

#Druid监控拦截相关配置相关配置
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
#缺省sessionStatMaxCount是1000个
session-stat-max-count: 1000
#关闭session统计功能
session-stat-enable: false
#druid 0.2.7版本开始支持profile,配置profileEnable能够监控单个url调用的sql列表。
profile-enable: false

#StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
#启动项目后访问 http://127.0.0.1:8080/druid
stat-view-servlet:
enabled: true
url-pattern: /druid/*
#禁用HTML页面上的“Reset All”功能
reset-enable: false
login-username: admin
login-password: admin
#IP白名单(没有配置或者为空,则允许所有访问)
allow: 127.0.0.1,192.168.56.101
#IP黑名单 (存在共同时,deny优先于allow)
deny: 192.168.1.102
redis:
#url: 127.0.0.1:6379
#database: 16
cache-expire: 1800
pool:
max-active: 10
max-wait: 10000
max-idle: 20
min-idle: 5
cluster:
nodes: 192.168.56.101:7000,192.168.56.101:7001,192.168.56.101:7002,192.168.56.101:7003,192.168.56.101:7004,192.168.56.101:7005
max-redirects: 100

#mybatis配置指定配置文件路徑mapper路徑
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations:
- classpath*:com/iwant/imine/**/mysql/*.xml
- classpath*:mybatis/mappings/*/*.xml
#分页插件配置参数
pagehelper:
helper-dialect: Mysql
#分页参数合理化,默认false禁用.如果pageNum<1或pageNum>pages会返回空数据
reasonable: false
#为了支持startPage(Object params)方法增加了一个`params`参数来配置参数映射,用于从Map或ServletRequest中取值
#可以配置pageNum,pageSize,count,pageSizeZero,reasonable,orderBy,不配置映射的用默认值 配合params使用
support-methods-arguments: true
params: count=countSql;pageNum=pageNumKey;pageSize=pageSizeKey;

#log4j配置文件路径
logging:
config: classpath:log4j2.xml

#web容器配置
server:
# connection-timeout: 60
context-path: /imine-admin
port: 15730
tomcat:
uri-encoding: UTF-8



项目依赖配置:
compile ("javax.servlet:javax.servlet-api:${servlet_version}")
compile ("org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatis_spring_boot_version}"){
exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-jdbc'
}
compile ("org.springframework.boot:spring-boot-starter-jdbc:${spring_boot_version}"){
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
}
compile ("org.springframework.boot:spring-boot-starter:${spring_boot_version}"){
exclude module: "spring-boot-starter-logging"
}

compile ("com.alibaba:druid-spring-boot-starter:${druid_spring_boot_version}");

compile ("com.github.pagehelper:pagehelper-spring-boot-starter:${pagehelper_spring_boot_version}"){
exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
exclude group: 'org.mybatis.spring.boot', module: 'mybatis-spring-boot-starter'
}
compile ("com.github.pagehelper:pagehelper:${pagehelper_version}"){
exclude group: 'com.github.jsqlparser',module: 'jsqlparser'
}
compile ("com.github.jsqlparser:jsqlparser:${jsqlparser_version}")

compile ("com.alibaba:druid:${druid_version}")
compile ("mysql:mysql-connector-java:${mysql_version}")
说明,所有依赖都是目前的最新版本。
启动类:
@SpringBootApplication(scanBasePackages = {"com.iwant.imine"}) // same as @Configuration @EnableAutoConfiguration @ComponentScan
@ImportResource(locations = {"classpath:kaptcha.xml"})
@EnableTransactionManagement
@MapperScan(basePackages = "com.iwant.imine")
public class ApplicationBootstrap extends SpringBootServletInitializer{

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder.sources(ApplicationBootstrap.class);
return builder;
}

public static void main(String[] args) {
SpringApplication.run(ApplicationBootstrap.class, args);
}
}
没有单独定义druid数据源配置了(因为使用了阿里巴巴的spring-boot-druid-starter)
这样配置后项目正常访问,当执行业务错误后,事务为进行回滚。请各位大神帮忙看看到底哪里有问题。万分谢谢!
已邀请:

Joyce_LN

赞同来自:

service类上加@Transactional注解了吗?

muncie

赞同来自:

配置文件没看出问题, 检查是否抛出RuntimeException, 如果是部分service事务失效, 检查下有没有service层互相调用的情况, 如果使用shiro, 检查 realm是否调用service, 都可能导致事务失效

要回复问题请先登录注册