Spring的InvalidDataAccessApiUsageException的怪异行为在同一catch块中被调用两次

时间:2019-06-05 21:35:48

标签: spring spring-boot spring-data-jpa

我在下面的服务方法中创建了company数据。 Company1:1具有CompanyType关系,company具有固定的一组值,并且无法插入更多值。这是一个只读表。因此,对于以下方法,我将错误的值(在DB中不存在)传递给InvalidDataAccessApiUsageException。当然public Company create(Company company) { Company createdCompany = null; try { company.setUser(userDao.findByEmail("abc@gmail.com") .orElseThrow(() -> new AccessDeniedException("You are not authenticated for this operation"))); createdCompany = companyDao.save(company); } catch (InvalidDataAccessApiUsageException ex) { // will be thrown if the company-type provided doesn't exist. // LOGGER.error(ex.getMessage()); LOGGER.error("*********************************************************"); throw new BadRequestException("Selected company type/category doesn't exist"); } return createdCompany; } 将在Spring之前抛出。但是我注意到catch块被调用了两次。这不是奇怪的行为吗?

2019-06-06 03:03:27 ERROR c.o.s.i.CompanyServiceImpl - *********************************************************
2019-06-06 03:03:27 ERROR c.o.s.i.CompanyServiceImpl - *********************************************************

日志

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class webdriverdemo {
     public static void main(String[] args) {
      // call test classes
       Example1 ex1 = new Exmple1();
       Example2 ex2 = new Example2();
     }
 }

 public class Example1  {

        public String baseUrl= "http://www.google.com/";

        public WebDriver driver = new FirefoxDriver();

        @Test

          public void verifyHomePageTitle() {
                // do something
               }

        }

   public class Example2  {

        public String baseUrl= "http://www.google.com/";

        public WebDriver driver = new FirefoxDriver();

        @Test

          public void verifyHomePageTitle() {
                // do something
               }

        }

0 个答案:

没有答案