spring+springmvc+mybatis+shiro事务回滚失败

爬行的小马驹 2017-03-22 03:21:17
路过的大神们,我执行一个任务的时候的控制台log如下,抛了异常,但是数据库的数据没有回滚。
求赐教。

14:49:57.800 DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Unable to resolve session ID from SessionKey [org.apache.shiro.web.session.mgt.WebSessionKey@2853c097]. Returning null to indicate a session could not be found.
14:50:01.787 DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
14:50:01.841 DEBUG org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@26490db8]
14:50:02.146 DEBUG org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@ff9bcb] will be managed by Spring
14:50:02.683 DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@26490db8]
14:50:06.597 DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@26490db8]
14:50:06.598 DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@26490db8]
14:50:06.598 DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@26490db8]
三月 22, 2017 2:50:06 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springServlet] in context with path [/ws] threw exception [Request processing failed; nested exception is com.ydkj.common.exception.BusinessException: exception] with root cause
com.ydkj.common.exception.BusinessException: exception
at com.ydkj.product.article.service.impl.ArticlePraisesServiceImpl.saveArticlePraises(ArticlePraisesServiceImpl.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)


spring-context.xml文件内容
[code=text]
<!-- 使用Annotation自动注册Bean,解决事务失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
<context:component-scan base-package="com.ydkj">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<!-- 加载配置属性文件 -->
<context:property-placeholder ignore-unresolvable="true" location="classpath*:properties/webview.properties" />
<context:property-placeholder ignore-unresolvable="true" location="classpath*:properties/base_config.properties" />
<context:property-placeholder ignore-unresolvable="true" location="classpath*:properties/redis.properties" />
<!-- 数据源配置, 使用 Druid 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
<property name="driverClassName" value="${jdbc.driver}" />

<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="${jdbc.pool.init}" />
<property name="minIdle" value="${jdbc.pool.minIdle}" />
<property name="maxActive" value="${jdbc.pool.maxActive}" />

<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />

<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />

<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />

<property name="validationQuery" value="${jdbc.testSql}" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />

<!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> -->

<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat" />
</bean>

<!-- Mybatis配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myP6DataSource" />
<property name="typeAliasesPackage" value="com.ydkj" />
<property name="mapperLocations" value="classpath:/mappings/**/*.xml" />
<property name="configLocation" value="classpath:/mybatis-config.xml" />
</bean>

<!-- 扫描basePackage下所有以 @MyBatisDao注解的接口注解的接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<property name="basePackage" value="com.ydkj"/>
<property name="annotationClass" value="com.ydkj.common.persistence.annotation.MyBatisDao" />
</bean>

<!-- 配置SQLSession模板 -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<!-- 声明式事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="select*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="query*" read-only="true" propagation="SUPPORTS"/>
<!-- 开启新事务 -->
<tx:method name="error*" propagation="REQUIRES_NEW"/>
<tx:method name="*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* *..*ServiceImpl.*(..))||execution(* com.ydkj.*.service.*.*(..))||execution(* com.ydkj.*.*.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
</aop:config>

<!-- <aop:aspectj-autoproxy proxy-target-class="true"/> -->
<!-- 使用annotation注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<import resource="classpath*:spring-context-shiro.xml"/>
</beans>
spring-mvc.xml文件内容
[/code
<!-- 使用Annotation自动注册Bean,只扫描@Controller -->
<context:component-scan base-package="com.ydkj" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>

<mvc:interceptors>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
<bean class="com.ydkj.ws.Interceptor.SpringMVCInterceptor"/>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
<bean class="com.ydkj.ws.Interceptor.SpringMVCInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>

<!--Spring3.1开始的注解 HandlerMapping -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<!--Spring3.1开始的注解 HandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />

<!-- 视图解释类 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="${web.view.prefix}" />
<property name="suffix" value="${web.view.suffix}" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean>

<!-- 定义无Controller的path<->view直接映射 -->
<mvc:view-controller path="/ws" view-name="redirect:${web.view.index}"/>

<!-- 对静态资源文件的访问, 将无法mapping到Controller的path交给default servlet handler处理 -->
<mvc:default-servlet-handler />
这个配置为啥事务不起作用。我在service实现类上都打了@service注解了。
...全文
663 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
啧啧 2018-02-28
  • 打赏
  • 举报
回复
有的说法是 spring 无法维护 shiro的 realm 。 所以需要在spring启动起来后再给 shiro 设置 realm 。 找了一些资料但是还没解决,尝试中。 可以看下这个 http://blog.csdn.net/fengfeng1229/article/details/76640080

5,655

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧