1

I want to configure Spring to redirect all the requests to a specific Controller irrespective of the URL (length and parameters). How should I give the URL pattern / regular expression in the RequestMapping annotation. I tried using the below code, but it is not working. Any help in this regard is deeply appreciated.

 @Controller @RequestMapping("/*") public class ServiceController { @RequestMapping( method = RequestMethod.GET, value = "*" ) public void getProjectList(HttpServletRequest httpServletRequest,Model model){ } } 
0

2 Answers 2

7

You need @RequestMapping(method = RequestMethod.GET, value = "/**").

From http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-patterns:

In addition to URI templates, the @RequestMapping annotation also supports Ant-style path patterns (for example, /myPath/*.do).

From http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html:

The mapping matches URLs using the following rules:

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path
Sign up to request clarification or add additional context in comments.

1 Comment

We have before used the above controller mapping without the method parameter, for a maintenance server to show that server is currently under maintenance. It works...
0

Have you tried with a regular expression?

Something like:

@RequestMapping("/{value:.}") 

1 Comment

You want to change the request mapping on the top of class or on the top of the method. I tried in all possible ways, but it is not working.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.