4

The following URL used to return 200 with Spring Boot 2.5

http://localhost:8080//actuator/health

After upgrading to 2.6 it no longer works and returns 404 Not Found

I spotted the error because some of the project's integration tests were failing (requests returned 404). Then I noticed the double slash, and after removing it, the issue was fixed.

I just want to understand which feature causes this new behavior?

I went through the 2.6 release notes several times, but nothing rings a bell.

glennsl
  • 28,186
  • 12
  • 57
  • 75
kirshiyin
  • 141
  • 1
  • 9
  • 2
    If you're using Spring MVC, this may be due to the change to the default path matching strategy: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#pathpattern-based-path-matching-strategy-for-spring-mvc. – Andy Wilkinson Jan 06 '22 at 14:26
  • @AndyWilkinson I tried setting it back to spring.mvc.pathmatch.matching-strategy to ant-path-matcher but the double slash variant still doesn't work.. – kirshiyin Jan 06 '22 at 14:52
  • 1
    As described in the last paragraph of that section in the release notes, that is to be expected: "Note that the path matching strategy for actuator endpoints is not configurable via a configuration property." – Andy Wilkinson Jan 06 '22 at 15:01
  • Ok, it makes sense. The path matching strategy was changed and cannot be configured for the actuator endpoints, which is exactly my case. – kirshiyin Jan 07 '22 at 13:19

3 Answers3

4

The issue was that the path matching strategy has changed. The actuator path pattern CANNOT be overwritten by

spring.mvc.pathmatch.matching-strategy=ant-path-matcher

The solution was to manually fix the URLs containing double slashes.

kirshiyin
  • 141
  • 1
  • 9
1
  1. Are you able to access actuator endpoint with single slash? like http://localhost:8080/actuator/health

  2. If yes, then did you configure the spring security for your application? There is a configuration you can define where your application will allow consecutive slashes in url.

    @Bean
    HttpFirewall httpFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
        firewall.setAllowUrlEncodedDoubleSlash(true);
        return firewall;
    }
    
  • 1. Yes 2. I don't have spring security in the project. As I mentioned, the 2.5 version was working with // in the URL. I am just trying to find out an explanation what caused the change in the behavior. – kirshiyin Jan 06 '22 at 14:00
1

here maybe the reason : PathPattern Based Path Matching Strategy for Spring MVC

The default strategy for matching request paths against registered Spring MVC handler mappings has changed from AntPathMatcher to PathPatternParser.

fix:

spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Liang
  • 11
  • 1