SpringBoot2 (eight) RequestMapping Notes

These days when using SpringBoot2 found a lot of weird bug, the same configuration, the problem does not occur in the Spring, under SpringBoot suddenly cropped up.

 

Use wildcards:

  To reduce the configuration page, often use wildcards, such as the following code, is to: Url core automatically match the same file folder.

  @RequestMapping(value = "core/**", method = RequestMethod.GET)
  public void ueditor() {
  }

  But in SpringBoot, which is very dangerous, if the page is not found, the code will try to find the path that matches with it automatically forwards the page to help us, still can not find after forwarding, then continue forward, always the target page not found They had unlimited forwarding, eventually leading to memory overflow (the phenomenon so far no view source code).

  The following log: Because the core / excel path was not found, DispatcherServlet even automatically stitching path, then page forward, forward, or can not find the finish, then the more the path of joining the longer, the last memory overflow.

2019-12-17 00:32:46.614 [http-nio-8081-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - "FORWARD" dispatch for GET "/Sea/core/
excel/core/excel/core/excel/core/excel/core/excel/core/excel/core/excel/core/excel/list?_bust=1576513963087", parameters={masked}

  A simple approach is at the end of the path suffix

  @RequestMapping(value = "core/**/*.ftl", method = RequestMethod.GET)
  public void markdown() {
  }

 

Static resources and templates do not take the same name:

  Under static resource files are directly accessible files under template, after configuration before use, which creates a problem: put on a file with the same name will be how?

  For example: In the static folders put a.js, then put in the template folder a.ftl, two paths are then provided to a prefix like, using 'xx / xx / a' path access, obviously, only which one can visit.

  Then there was a bold idea: to let the program automatically to identify either placed a.js in static, or to be placed in the template a.ftl, which documents exist, which automatically acquired, but, unfortunately, this design is It is not allowed.

  Moreover, following this wildcard configuration is not allowed, it will not go to static resources, determine the template file can not be found, directly reported 404 errors.

  @RequestMapping(value = "core/**", method = RequestMethod.GET)
  public void ueditor() {
  }


  Under Servlet need very clear that the last extension request, often simply ignored by the program, such as http: //localhost/xx/1.png, rearmost ".png" is likely to be ignored if the same name exists file 1.jpg, be sure to check the implementation of the code.

 

 

Guess you like

Origin www.cnblogs.com/chenss15060100790/p/12052328.html