SpringBoot transaction rollback

1, Controller code

   @PostMapping("/add")
   public RestResult add(ModelParamInputDTO modelParamDTO) {
       this.isValid("modelName", modelParamDTO.getModelName());
       this.isValid("drugId", modelParamDTO.getDrugId());
       this.isValid("drugCode", modelParamDTO.getDrugCode());
       aiModelService.addAiModel(modelParamDTO);
       return ResultGenerator.genSuccessResult().setMessage("");
   }
   
   @PostMapping("/isValid")
   public RestResult isValid(@RequestParam String key, String value) {
       Boolean isValid = aiModelService.isValid(key, value);
       if (isValid) {
           return ResultGenerator.genSuccessResult();
       } else {
           String[] ret = {""};
           VALID_MESSAGE.forEach((k, v) -> {
               if (k.equals(key)) {
                   ret[0] = v;
               }
           });
           throw new ServiceException(ret[0]);
       }
   }

2, service code

@Override
@Transactional(rollbackFor=Exception.class)
public void addAiModel(ModelParamInputDTO modelParamDTO) {

    String modelId = CoreUtils.getUUID();
    AiModel aiModel = new AiModel();
    BeanUtils.copyProperties(modelParamDTO, aiModel);
    aiModel.setId(modelId);
    aiModel.setOrgId(ORG_ID);
    aiModel.setGmtCreate(new Date());
    aiModel.setModelName(modelParamDTO.getDrugName());
    aiModelMapper.insert(aiModel);
    String s = null;
    int d = s.length();               
}

3, Application code

@SpringBootApplication
@MapperScan("cn.itpower.pms.modules.**.dao")
@EnableConfigurationProperties
@EnableTransactionManagement
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
The

code is like this. I set a null pointer exception myself, but the transaction is not rolled back. I tried:

TransactionAspectSupport.currentTransactionStatus (). SetRollbackOnly ();
as a result, the transaction is still not rolled back. What on earth is going on?

Mar.28,2021

whether comments have been added to Application

   @PostMapping("/add")
   public RestResult add(ModelParamInputDTO modelParamDTO) {
       this.isValid("modelName", modelParamDTO.getModelName());
       this.isValid("drugId", modelParamDTO.getDrugId());
       this.isValid("drugCode", modelParamDTO.getDrugCode());
       aiModelService.addAiModel(modelParamDTO);
       return ResultGenerator.genSuccessResult().setMessage("");
   }

there may be a problem with the above code, is it related to the lack of annotation @ RequestBody?
in addition, Controller does not use dto to receive parameters, use VO.

Menu