Yesterday while developping ukazbobra I realized, that I don’t know how to map controller for my index view in root of Spring MVC project. I searched and experimented a bit and here is a solution. Please note I’m using Spring Roo and annotation driven setup.

First thing is to create controller, for example simple one like this:

@RequestMapping("/")
@Controller
public class RootController {

	@RequestMapping(method = RequestMethod.GET)
	public String index(Model model) {
		model.addAttribute("foo", "bar");
		return "index";
	}
. . .

Now you have to turn off thing named ParameterizableViewController, which staticaly selects a view for for rendering. So open up webmvc-config.xml and remove line with mapping for index view:

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

That is all, nothing more, nothing less – you have working controller for your index page in root and also for other views.