0
似乎像春天忽略@服务类上的事务注释。 我读了一些q&a on SO和blogs但没有任何选项似乎为我工作。Spring忽略@Transactional注释
- 我没有调用一个私有方法 - 我调用了一个公开的方法,它暴露在接口上。
- 我正在调用另一个类的方法(即不能从同一个类调用)。
- 我的“服务”类注释为
@Component
和@Transactional
。 - 我的“服务类有一个接口,而我使用的接口,将其注入,和
@Inject
注释 - 我尝试添加
proxy-target-class="true"
这里描述的一个答案 - 。没有工作 - 我用JAX-RS“M(未弹簧-MVC)
DAO层,用@Transactional(propagation = Propagation.MANDATORY)
,注释当出现此例外上发生的错误:
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
以下是一些代表相关类别和接口的通用代码:
public interface IService<T extends BaseEntity> {
void save(T entity);
}
public abstract class AbstractService<T extends BaseEntity> implements IService<T> {
@Inject
private IDao dao;
@Override
public void save(T entity) {
dao.save(entity);
}
}
public interface IPersonService extends IService<PersonEntity> {
void saveAll(List<PersonEntity> persons);
}
@Component
@Transactional
public class PersonService extends AbstractService<PersonEntity> implements IPersonService {
@Override
public void saveAll(List<PersonEntity> persons) {
for (PersonEntity person : persons) {
super.save(person);
}
}
}
@Component
public class PersonApi {
@Inject
private IPersonService personService;
public void saveAll(...) {
...
personService.saveAll(persons);
}
}
任何想法或建议吗?
而且,如果您在相同的类上调用方法,则这些都不重要。 AOP仅适用于外部方法调用,不适用于内部方法调用。但是,由于您没有添加代码,因此无法查看错误的位置。 –
是什么让你觉得它不起作用?你能分享一些代码吗? – Leffchik
我不是从同一个班级调用该方法。正如我所说,我使用它的接口注入服务,并使用接口来调用它。 我正在提供一些代码示例... –