如果我将'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)
我尝试'aspectj'与'proxy-target-class =“true”'但没有帮助。没有mode =“aspectj”一切都很好:连接在存储库调用之后仍然按预期进行。
有一篇详细的文章,但这很长: http://doanduyhai.wordpress.com/2011/11/20/spring-transactional-explained/
任何提示?
问候: 本斯
答案 0 :(得分:0)
我知道这个问题有点陈旧,但也许以后可能会对某人有用,
我认为原因是你有:
<context:component-scan base-package="my.jpatest.dao.auth">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
</context:component-scan>
并且它说它必须只检查使用Repository注释注释的类,如果你还想要使用service注释的类,只需添加一个include行,如:
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
应该是它。