2

When I upgrade my Spring Boot API to 2.6.1 version, I am getting this error. URL ant matcher in my API likes: /v1/token/**.

Any solution for this error:

Invalid mapping pattern detected: /**/swagger-ui/**
^
No more pattern data allowed after {*...} or ** pattern element

Action:

Fix this pattern in your application or switch to the legacy parser 
implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.

I already added the spring.mvc.pathpattern.matching-strategy=ant_path_matcher to application.properties file, but it not works.

v.ladynev
  • 19,275
  • 8
  • 46
  • 67
Bapu
  • 59
  • 1
  • 10
  • 1
    Can you post your configuration to see more details. Though basically you can not use an all matching wildcard `**` followed by a hardcdoed literal and another wildcard. – Tobi Dec 20 '21 at 10:21
  • This is My configuration : webSecurity.ignoring().antMatchers("/token/**", "/v1/token/**", "/v2/token/**", "/v2/authenticate/**", "/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/index.html"); – Bapu Dec 20 '21 at 10:22
  • I cant find the matcher from the provided error. Can you post the stacktrace as well? And add your configuration to your answer please. In case the stacktrace tells you a line of code, please include them too. – Tobi Dec 20 '21 at 10:40
  • this is due to [spring 5.3.x upgrade](https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc)... solutions: or set that property, or find(, please!) this wildcards, and replace them (with something better suited). [non-resolved-duplicate](https://stackoverflow.com/q/69283400/592355) – xerx593 Dec 20 '21 at 10:44
  • ..springfox or springdoc?? – xerx593 Dec 20 '21 at 10:46
  • private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher( new AntPathRequestMatcher("/v2/**") // TODO: Only securing /v2 endpoints for second round, once ready should secure all endpoints with /** ); AuthenticationProvider provider; @Override public void configure(final WebSecurity webSecurity) { webSecurity.ignoring().antMatchers("/token/**", "/v1/token/**", "/v2/token/**", "/v2/authenticate/**", "/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/index.html"); } – Bapu Dec 20 '21 at 10:47
  • [one more (duplicate)](https://stackoverflow.com/q/70405474/592355), yesterday – xerx593 Dec 20 '21 at 10:47
  • @Override protected void configure(HttpSecurity http) throws Exception { http.sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .exceptionHandling() .and() .authenticationProvider(provider) .addFilterBefore(authenticationFilter(), AnonymousAuthenticationFilter.class) .authorizeRequests() .requestMatchers(PROTECTED_URLS) – Bapu Dec 20 '21 at 10:47
  • nono, i assume *not in your sources* but somehwere in (swagger-ui related) dependencies – xerx593 Dec 20 '21 at 10:48
  • .authenticated() .and() .cors() .and() .csrf().disable() .formLogin().disable() .httpBasic().disable() .logout().disable() ; } } – Bapu Dec 20 '21 at 10:48
  • (you can edit the post...) https://github.com/springfox/springfox/issues/776 – xerx593 Dec 20 '21 at 10:50

1 Answers1

0

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER add this in application.properties for me its working

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 05 '22 at 15:04