如spring docs所说,在类级别的事务注释将被继承到子类。
因此,如何覆盖此行为,例如,我在子类中具有公共方法,并且我不希望该方法具有事务性。
我尝试使用
声明子类方法@Transactional(传播=传播。NOT_SUPPORTED)
但是,它仍然应用超类的事务配置。
@Service
@Transactional
public class EmployeeServiceImpl extends AbstractEmployeeServiceImpl {
private EmployeeDao employeeDao;
private AddressDao addressDao;
@Autowired
public EmployeeServiceImpl(EmployeeDao employeeDao, AddressDao
addressDao) {
this.employeeDao = employeeDao;
this.addressDao = addressDao;
}
// other service methods here ...
}
public interface OtherEmployService {
public void someMethod();
}
@Service
public class FooServiceImpl extends EmployeeServiceImpl implements OtherEmployService {
@Autowired
public FooServiceImpl(EmployeeDao employeeDao, AddressDao addressDao) {
super(employeeDao, addressDao);
}
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED) // it does not work, and still creates new transaction
public void someMethod() {
TransactionAspectSupport.currentTransactionStatus().isNewTransaction(); // provides new transaction
}
}
那么,如何使someMethod()非事务性?