Spring Controller方法中InitdirectFieldAccess的问题
我看到一个非常奇怪的行为。我有一个弹簧控制器方法,该方法将单个参数作为一个具有验证注释的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()”行,那么这些方法几乎没有时间。
- 因此,可能是由于句子
binder.initdirectfieldaccess();
第一次太慢而成为原因? - 为什么第二次几乎没有时间之间的时间?某种缓存?
谢谢
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.
- So, may be the reflection the cause because of the sentence
binder.initDirectFieldAccess();
that is too slow the first time? - Why the next times takes almost no time between the methods? Some kind of caching?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论