shiro配置 AOP式方法级权限检查时 事务失效
< 返回列表时间: 2012-11-10来源:开源中国
HDC调试需求开发(15万预算),能者速来!>>>
当对shiro配置 AOP式方法级权限检查时:
<!-- AOP式方法级权限检查 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true" />
</bean>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
执行删除操作时(删除用户,同时删除用户下的任务)会报错:
Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:96)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:154)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:55)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:95)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:85)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:313)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
具体错误语句,我测试过应该是:
taskDao.deleteByUserId(id);
@Modifying
@Query("delete from Task task where task.user.id = :id")
void deleteByUserId(@Param("id") Long id);

如果修改为: taskDao.delete(id); delete(id)是JPA DATA中的方法,不会报错。
不配置AOP式方法级权限检查,也不会报错。
在quickstart和showcase都会存在,配置方法和showcase一模一样,showcase虽然有这个例子,也不会报错,但可惜这种情况,属于我的上面举的不报错的情况,调用的是JPA自带的delete方法。希望作者能看一下,看看是什么问题,也希望大家能解决一下。经过我测试,是不是JPA DATA 和 shior AOP式方法级权限检查有冲突,导致事务失效!!!
热门排行