Spring: How to redirect non-dispatcher requests to dispatcher?
I have standard servlet-mapping for Dispatcher Servlet - /app/*
. I have controller that handle /notify
requests. I need to expose this controller as servlet on http://[SERVER]/notify
. How to simple redirect all requests from http://[SERV开发者_Go百科ER]/notify
to http://[SERVER]/app/notify
(but without other tools, like urlrewrite) ? I know i can write simple servlet instead of, and set servlet-mapping in web.xml, but want to have controller, not servlet ;)
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
Controller:
@Controller
public class PaymentNotificationController {
@RequestMapping("/notify")
void notify() { ... }
}
You can put another Dispatcher Servlet in
<servlet-mapping>
<servlet-name>Notification Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/notify/*</url-pattern>
</servlet-mapping>
and configure it with the same XML file as your main dispatcher servlet.
Don't discount urlrewrite - it only takes nanoseconds to execute, and years have gone into making it as fast as possible.
If you do throw up another Spring MVC servlet, you'll wind up with a second application context, which may not be desirable. DispatcherServlet is a front controller, of which there is supposed to be one - so yes - you can put as many as you want in, but they're almost like little mini-apps inside your WAR.
精彩评论