Issues regarding usage of Spring MVC @RequestMapping methods
Questions tagged [request-mapping]
348 questions
10
votes
1 answer
How do I make @Controller mapping path configurable?
I'm building an internal library that should automatically add a few controllers to Spring MVC application. These controllers are all @RestController with a few handler methods annotated with @RequestMapping. Since it's a library, I want users to be…

Andrey Agibalov
- 7,624
- 8
- 66
- 111
9
votes
2 answers
@RequestMapping annotation in Spring MVC
I have a controller with request mapping as @RequestMapping("/**")
What does it mean?
If I want to exclude certain url pattern from the above mapping how would I do that?
Could someone please shed some light on it?

Chaitanya MSV
- 6,706
- 12
- 40
- 46
9
votes
2 answers
Using Spring's @RequestMapping with wildcards
This is similar to this question, but I am still confused about my situation. I want to map this ant-style pattern to a controller method:
/results/**
That is, I want any URL like www.hostname.com/MyServlet/results/123/abc/456/def/ to go to this…

Tony R
- 11,224
- 23
- 76
- 101
9
votes
4 answers
Spring @RequestMapping
I keep seeing this kind of param value = "/redirect/{id}" in a @RequestMapping annotation of the Spring. I keep wondering what is {id} here? Is this some sort of Expression Language?
Sample code of what I have seen:
@RequestMapping( value =…

user2785929
- 985
- 7
- 13
- 30
8
votes
3 answers
Spring - is it possible to give same url (path) in request mapping for two different post methods?
Is it possible to map same path (uri) in request mapping for two different post methods, only difference is request body.
Example
@RequestMapping(value = "/hello", method = RequestMethod.POST)
public String helloEmployee(@RequestBody Employee…

Ravikumar
- 413
- 1
- 7
- 18
6
votes
3 answers
Accept two different subclasses with same @RequestMapping
I have WebDeviceInfo and IOSDeviceInfo classes that are subclasses of DeviceInfo. How can I create a single endpoint in a Spring @RestController that will accept either IOSDeviceInfo or WebDeviceInfo?
Attempt #1
I tried to map the same…

Andrew Mairose
- 10,615
- 12
- 60
- 102
6
votes
3 answers
Matching anything in Spring RequestMapping
On Spring MVC rest service I am having issues trying to match anything that is beyond my configured RequestMapping value.
So for e.g. I have this:
@RequestMapping(value = "{configKey}/{arguments:.*}", method = RequestMethod.GET)
Which says that…

Paulius Matulionis
- 23,085
- 22
- 103
- 143
5
votes
2 answers
Avoid the slash(/) between Spring RequestMapping
Consider the following example:
@Controller
@RequestMapping({"/home"})
public class Home {
@RequestMapping(value = { "", "/" })
public String index() {
return "home";
}
@RequestMapping(value = { "-of-{id}" })
public…

knly
- 81
- 1
- 4
5
votes
1 answer
Spring MVC RequestMapping not working on RestController
I want to have a RestController-class with the base-mapping "/user" (so the different functions will have paths like "/user/add", "/user/remove" etc or use POST/GET etc)
This is the part that I don't understand and can't get to…

Juliette
- 966
- 16
- 35
5
votes
2 answers
RestTemplate ConnectException Unreachable
I don't understand this... I'm trying to catch a java.net.ConnectException in case my downstream API is offline. However Eclipse warns me that it's unreachable - suggesting the code cannot throw a ConnectException. However, it clearly…

Jim Taylor
- 111
- 2
- 10
5
votes
2 answers
Spring-MVC PathVariable matching regular expression not starting with word
I want to match all requests with a PathVariable which are not start with 'api'. I test following RequestMapping. spring could match request but could not get value for PathVariable. How I solve this?
@RequestMapping(value = "/{name:(?!api).+}",…

hadi.mansouri
- 828
- 11
- 25
5
votes
1 answer
Forward JSON POST request from one REST API to another
I have the following situation:
My REST API one:
@RestController
@RequestMapping("/controller1")
Public Class Controller1{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws…

user_abh
- 357
- 3
- 6
- 20
4
votes
2 answers
Spring @RequestMapping for everything except /api/ or /rest/ (negate specific word in regex)
I need a Spring @RequestMapping that I will use to match all non-/api/... paths like /products to forward them to my / (by return "forward:/";) view controller which actually serves index.html contents and causes frontend (React) application to be…

Piotr Müller
- 5,323
- 5
- 55
- 82
4
votes
1 answer
Enums as Request Parameters in Spring Boot Rest
I am new to spring boot and trying to use Enum as a parameter of a rest request.
This is my Enum class:
public enum Month {
JANUARY (1, "january"), FEBRUARY(2,"february"), MARCH(3,"march"),
APRIL(4,"april"), MAY(5,"may"), JUNE(6,"june"),…
user6941415
4
votes
3 answers
RequestMapping: How to access the "method" value used for a rest endpoint
I have a Spring Boot REST controller endpoint that accepts both GET and POST requests:
@RequestMapping(
value="/users",
method= {RequestMethod.GET, RequestMethod.POST},
headers= {"content-type=application/json"}
…

Vismark Juarez
- 43
- 4