Hello everyone,

We are trying to upgrade a very huge web app from Spring Framework version 5 to 6 (spring-webmvc-6.2.5).

We switched to path-pattern-matching because of the following error:

Caused by: java.lang.IllegalArgumentException: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).

This is because there is more than one mappable servlet in your servlet context: {org.apache.catalina.servlets.DefaultServlet=[], org.apache.jasper.servlet.JspServlet=[*.jspx, *.jsp], org.springframework.web.servlet.DispatcherServlet=[/]}.

We have nearly 1700 patterns configured, for example:

http.authorizeHttpRequests(auth -> auth
    .requestMatchers(mvc.pattern("GET", "/person/**"))
    .authenticated()
);

The application now starts up, but if the WebInvocationPrivilegeEvaluator is asked for permission it sometimes fails at:

Assert.state(this.pathPatternCache.size() < MAX_PATTERNS, "Max size for pattern cache exceeded.");
Caused by: java.lang.IllegalStateException: Max size for pattern cache exceeded.
    at org.springframework.util.Assert.state(Assert.java:79)
    at org.springframework.web.servlet.handler.PathPatternMatchableHandlerMapping.lambda$match$0(PathPatternMatchableHandlerMapping.java:63)

I guess it fails on the patterns that are configured last. Is there a reason for MAX_PATTERNS = 1024? Can I somehow get around that limit?

Thanks

Comment From: sbrannen

Hi @neekibo,

Congratulations on submitting your first issue for the Spring Framework! 👍

Is there a reason for MAX_PATTERNS = 1024?

It is arbitrarily large, however apparently not large enough for your particular use case.

Can I somehow get around that limit?

Currently, no.

However, we plan to make the max size configurable in 6.2.x.

I have therefore reworded the title of this issue to reflect that.