Why does Spring's @RequestMapping annotation in the controller grab more of what I want?

I have a simple Spring controller with a display:

@Controller
public class HomeController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
    public String home(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model Principal principal) {
        ...
        return "home";
    }
}

      

Naturally it grabs http://localhost:18080/XXX/home

but why does it grab links like http://localhost:18080/XXX/home.error

or http://localhost:18080/XXX/home.qwe123.234

etc. I didn't set the display for home.error or home.qwe123.234 etc. anywhere. I only have a display in my controllers. How do I stop the controller to match this?

+3


source to share


1 answer


Since the default sets Spring MVC environment PathMatchConfigurer

for which the useSuffixPatternMatch

set value true

. From javadoc

Whether to use the suffix pattern (".*")

when matching patterns with Requests. If enabled, the method associated with "/users"

is also matched "/users.*"

.

Default value true

.



You can set it to false

in your MVC config if your class @Configuration

extends WebMvcConfigurationSupport

and overrides

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setUseSuffixPatternMatch(false);
}

      

+7


source







All Articles