Spring 数据Mongo,为什么异常不是 DuplicateKeyException 的实例?

Spring Data Mongo, why exception is not instance of DuplicateKeyException?

我正在处理 Spring Boot Rest MongoDB 示例。在此示例中,我有 Student 集合,其中 emailId 是唯一字段(我在 unique=true 处应用了索引)。当有人创建新 Student 并使用 Mongo 中已经存在的 emailId 时,我应该得到 DuplicateKeyException。但不知何故 ex 对象不是 DuplicateKeyException 的一部分。为什么不是 DuplicateKeyException 的实例?

try {
    studentRepository.save(student);
} catch (Exception ex) {
    if(ex instanceof DuplicateKeyException) {
        throw new DuplicateResourceFoundException("studentName already present");
    }
    throw new DuplicateResourceFoundException("studentName already present");


    //throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, env.getProperty("error.db.exception"), ex);
} 

我能够解决这个问题。我犯了一个简单的错误,import should have been done from org.springframework.dao.DuplicateKeyException。现在这工作正常。