小编Kry*_*n G的帖子

为什么 Spring Boot 会为 Controller 方法参数验证抛出不同的异常?

在使用约束验证注释(@Min、@NotNull、...)验证原始类型或其等效项(整数、布尔值)时,Spring Boot 抛出ConstraintViolationException. 但是当使用@Valid注释验证参数时,则MethodArgumentNotValidException抛出。

我有一个注释的类@ControllerAdvice来处理来自控制器的异常。问题是,根据spring-boot-starter-parent版本的不同,结果会大不相同。在使用该版本时,2.0.5.RELEASE我只需要为ConstraintViolationException该类包含一个处理程序。但是还有一些其他版本也MethodArgumentNotValidException被抛出。

它已经在GitHub 问题上提到过,但没有有用的答案......

我将在这里使用 lukasniemeier-zalando 的例子。有关更多详细信息,请单击上面的链接。

 @Validated  // needed to actually trigger validation
 @RestController
 class MyController {

   @RequestMapping
   Response serve(
     @RequestParam @Min(2) Integer parameter,  // throws ConstraintViolationException
     @RequestBody @Valid BodyModel body        // throws MethodArgumentNotValidException
     ) {
       return new Response();
     }

 }
Run Code Online (Sandbox Code Playgroud)

我希望两个验证都抛出相同的异常,无论是哪一个,只是为了保持一致。

显然没有理由像这样,至少这是我从另一个GitHub 问题中了解到的。

然后我只想知道为什么 Spring Boot 会抛出 2 种类型的异常来表示相同的问题(参数验证)。

:为使用的版本之前所提到的,2.0.5.RELEASEspring-boot-starter-parent它不会发生。 …

spring-boot

7
推荐指数
1
解决办法
2690
查看次数

如何使用 Selenium 和 Python 更改用户代理

我在使用 selenium 更改 Python 中的 Web 驱动程序用户代理时遇到错误。

这是我的代码:

import requests
import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Chrome(driver_path) driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'})
#Error is on line above
Run Code Online (Sandbox Code Playgroud)

这是我的错误:

>>> driver = webdriver.Chrome(driver_path) driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent":"python 3.7", "platform":"Windows"})
  文件“<stdin>”,第 1 行
    driver = webdriver.Chrome(driver_path) driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent":"python 3.7", "platform":"Windows"})```

python selenium user-agent webdriver selenium-webdriver

5
推荐指数
1
解决办法
2万
查看次数

安卓BLE扫描

O/S Android 11。我开发了一个带有 BLE 扫描的应用程序。它不与 BLE 设备进行任何连接。它只是获取附近设备的列表。应用程序运行良好。每次停止和启动扫描时,我都可以在 Logcat 中看到以下错误。谁能告诉我出了什么问题吗?

E/BtGatt.GattService: [GSIM LOG]: gsimLogHandler, msg: MESSAGE_SCAN_START, appName: com.ttt.ttt.vctap, scannerId: 11, reportDelayMillis=0
E/BtGatt.GattService: [GSIM LOG]: gsimLogHandler, msg: MESSAGE_SCAN_STOP, appName:com.ttt.ttt.vctap, scannerId: 11, reportDelayMillis=0 
Run Code Online (Sandbox Code Playgroud)

java android bluetooth-lowenergy

1
推荐指数
1
解决办法
1829
查看次数