I'm making my first steps in Spring MVC, and I'm probably missing something, since this doesn't make sense to me:
I started with the mvn-basic spring sample, and got it to run. Then I wanted to see if I can make it work on a sub-path, so that I can use it alongside legacy code that I have. I made the following changes:
In servlet-context.xml:
- <mvc:view-controller path="/" view-name="welcome"/> + <mvc:view-controller path="/web/" view-name="welcome"/>
In AccountController.java:
-@RequestMapping(value="/account") +@RequestMapping(value="/web/account")
In web.xml:
- <url-pattern>/</url-pattern> + <url-pattern>/web/*</url-pattern>
I also increased the logging to DEBUG. I rebuilt and tried running, but trying to access http://localhost:8080/web/account resulted in 404, and "No mapping found" in the log, even though earlier in the log I can see "Mapped URL path [/web/account] onto handler 'accountController'".
I discovered that if I undo the changes to web.xml, everything works, but then the DispatcherServlet takes over all the requests.
So I have two questions:
- What am I doing wrong? How can I limit the DispatcherServlet to a subsection of the site?
- How does it even work in the first place? The demo seems to only send requests to "/" to the DispatcherServlet, so how come "/account" also works?
I'm using Spring 3.0.5.RELEASE
UPDATE: The solution is to leave the request mapping is at was, thanks @axtavt. Otherwise the URL becomes http://localhost:8080/web/web/account (notice the duplicate /web
). I would still like an answer to my second question, though.