Spring Controller方法中InitdirectFieldAccess的问题

发布于 2025-02-13 04:27:46 字数 957 浏览 0 评论 0原文

我看到一个非常奇怪的行为。我有一个弹簧控制器方法,该方法将单个参数作为一个具有验证注释的Javabean对象和initbinder方法允许 InitdirectFieldAccess。代码就像下一个:

@InitBinder
public void initBinder(WebDataBinder binder) {    
    binder.initDirectFieldAccess(); 
    log.info("ending initBinder");  
}




@PostMapping    
public @ResponseBody ResponseEntity<OpValidateResponse> validateClient(
        @RequestBody @Valid OpValidateRequest request) {
    log.info("Beginning execution of method");
    final OpValidateResponse response = validateClientService
            .validateClient(sanitizeXSSForObject(request));
    return ResponseEntity.ok().body(response);
}

Wierd的事情是,在Initbinder方法中的记录“ Ending Initbinder”之间,登录“启动执行方法的执行方法”该方法首次在6-10秒之间调用,但下一个执行方式不是。如果我评论“ binder.initdirectfieldaccess()”行,那么这些方法几乎没有时间。

  1. 因此,可能是由于句子binder.initdirectfieldaccess();第一次太慢而成为原因?
  2. 为什么第二次几乎没有时间之间的时间?某种缓存?

谢谢

I am seeing a really wierd behaviour. I have a Spring controller method that take as a single parameter a JavaBean object that has validation annotations and an initBinder method to allow
initDirectFieldAccess. The code is like the next:

@InitBinder
public void initBinder(WebDataBinder binder) {    
    binder.initDirectFieldAccess(); 
    log.info("ending initBinder");  
}




@PostMapping    
public @ResponseBody ResponseEntity<OpValidateResponse> validateClient(
        @RequestBody @Valid OpValidateRequest request) {
    log.info("Beginning execution of method");
    final OpValidateResponse response = validateClientService
            .validateClient(sanitizeXSSForObject(request));
    return ResponseEntity.ok().body(response);
}

The wierd thing is that between the logging "ending initBinder" in initBinder method and the logging "Beginning execution of method" of validateClient method takes just the first time the method is called between 6-10 seconds but the next executions just not. If I comment the line "binder.initDirectFieldAccess(); ", there is almost no time between those methods ever.

  1. So, may be the reflection the cause because of the sentence binder.initDirectFieldAccess(); that is too slow the first time?
  2. Why the next times takes almost no time between the methods? Some kind of caching?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文