Spring mvc performance drops significantly when adding more controllers Spring mvc performance drops significantly when adding more controllers spring spring

Spring mvc performance drops significantly when adding more controllers


What you can do without change Spring code, is to refactor your code to use only one RequestMapping which matches all problematic patterns and write some perfomant algorithm by yourself to delegate the calls to the right classes and pass the parameters.

You can start the algorithm with a if tree and some regex, don't forget to compile the regex and save it to a constant, this way you will not have performance issues.


You can perform better in a couple of ways:

  • write a single controller and manually handling the path /v1/foo/{foo}/bar/{bar}/{animal} and perform a switch case inside each method of the controller
  • use a single controller and delegates the pattern to single methods instead of class. If there is a method that is performed more frequently than others put it at the beginning of the class so that it will be checked as first