views:

896

answers:

3

Is it possible to use multiple @RequestMapping spring annotations in a method? Like:

@RequestMapping("/")
@RequestMapping("")
@RequestMapping("/welcome")
public String welcomeHandler(){
 return("welcome");
}
+2  A: 

Doesn't need to. RequestMapping annotation supports wildcards and ant-style paths. Also looks like you just want a default view, so you can put

<mvc:view-controller path="/" view-name="welcome"/>

in your config file. That will forward all requests to the Root to the welcome view.

BrennaSoft
Is there supposed to be something between those two lines?I am using the FreeMarkerViewResolver - so I would have to go this way... Well, I guess I could just create multiple ViewResolver.
wuntee
+3  A: 

@RequestMapping has a String[] value parameter, so you should be able to specify multiple values like this:

@RequestMapping(value={"", "/", "welcome"})

Ed Brannin
That said, I'm having trouble getting the "" or "/" values to actually work in my application. Do they work for you?
Ed Brannin