I want to map the spring mvc controller to the root ( /** ) path (and not a subfolder such as "/ something"), making exceptions with mvc:resources (open to another method).
It should be the ABC of this structure, but it seems to be very complex material to ask about it.
My app-servlet.xml has these obvious exceptions:
<mvc:resources mapping="/favicon.ico" location="/favicon.ico" /> <mvc:resources mapping="/robots.txt" location="/robots.txt" />
And I have this controller:
import java.util.Date; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/**") public class MainController { @RequestMapping(method = RequestMethod.GET) public String service(final HttpServletRequest request) { final String servlet_path = request.getServletPath(); System.out.println(String.format("%s %s", new Date().toString(), servlet_path)); return "test"; } }
Now when I press "/" or "/ test" or "/ test / page", I get the output, for example:
Fri Aug 03 00:22:12 IDT 2012 / Fri Aug 03 00:22:13 IDT 2012 /favicon.ico
.. cm.? service() is called for /favicon.ico , even if it is explicitly excluded!
Now I assume that there is some βpriorityβ for @Controller in XML, however, how do I get the exception working?
A simple requirement is on the "/" website.
PS This answer answers a very similar question.
One more note: this question is not about the tomcat context.