如果我将 'mode="aspectj"' 放入 'tx:annotation-driven' 标记中,则 Spring-data 仅处理 @Repository 文件中的事务,而不是 @Service 类中的事务。
这是我的@Service 来检索用户:
@Service
public class RepositoryAuthService implements AuthService{
@Resource
AuthUserRepository userRepository;
@Transactional(propagation = Propagation.REQUIRED)
@Override
public User findByCredentials(String userName, String password){
User user = userRepository.getByCredentials(userName, password);
TransactionAspectSupport.currentTransactionStatus().toString();
...
}
这是我的弹簧上下文:
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
<jpa:repositories base-package="my.jpatest.dao.auth" />
<context:component-scan base-package="my.jpatest.dao.auth">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
</context:component-scan>
<bean class="my.jpatest.dao.auth.RepositoryAuthService" id="authService" />
例外:
org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
at org.springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus(TransactionAspectSupport.java:111)
at my.jpatest.dao.auth.RepositoryAuthService.findByCredentials(RepositoryAuthService.java:34)
我用 'proxy-target-class="true"' 尝试了 'aspectj' 但没有帮助。如果没有 mode="aspectj" 一切都很好:在存储库调用之后,连接仍然如预期的那样。
有一篇详细的文章,但这很长: http ://doanduyhai.wordpress.com/2011/11/20/spring-transactional-explained/
有小费吗?
问候:本斯