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
我不是從同一個班級調用該方法。正如我所說,我使用它的接口注入服務,並使用接口來調用它。 我正在提供一些代碼示例... –