DataIntegrityViolationException
をキャッチしてそれを私のカスタム例外に変換しようとすると、catchブロックは実行されません。私はこれからコードを使用例として Spring TransactionTemplateは例外を処理しません
、ServicePointRepository
は私のコントローラレイヤで処理されるDataIntegrityViolationException
をスローし、実行時にコードがcatchブロックを避けているようです。
私は間違っていますか?
これはPersistenceServiceからのコードです:
@Autowired
private ServicePointRepository servicePointRepository;
@Autowired
private BusinessExceptionFactory businessExceptionFactory;
@Autowired
private TransactionTemplate transactionTemplate;
@Override
public String save(final ServicePointDTO servicePointDTO) {
final ServicePointEntity servicePointEntity = mapToEntity(servicePointDTO);
return transactionTemplate.execute(status -> {
try {
return servicePointRepository.save(servicePointEntity).getId().toString();
} catch (DataIntegrityViolationException e) {
throw businessExceptionFactory.createBusinessException(AlreadyExistException.class, CommonError.ALREADY_EXIST);
}
});
}