Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15831

MockMvc doesn't honor params in RequestMapping when no equal sign

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.10, 5.0 RC3
    • Fix Version/s: 5.0 RC4
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      When two resource methods are defined as following:

          @GetMapping
          public String noParam() {
              return "noParam";
          }
      
          @GetMapping(params = "foo")
          public String paramFoo() {
              return "paramFoo";
          }
      

      and a MockMvc test tries executing the second method using

          mvc.perform(get("/api/bug?foo"))
      

      then the first method is invoked instead. Adding an equal sign at the end fixes the issue, but the equl sign shouldn't be necessary. BTW, in production, sending a request to /api/bug?foo does invoke the second method as expected.

      Here's a repro project: https://github.com/jnizet/param-bug-demo

      Note that the original bug has been detected in a Spring Boot 2.0.0.M2 project, so the bug is still there in the latest version of Spring.

        Attachments

          Activity

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              jnizet Jean-Baptiste Nizet
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                46 weeks, 4 days ago