Alex Rivera | Logout

Spring MVC Request mapping, can this be dynamic/configurable?

Asked 2012-10-03T14:09:00.887
14

With Spring MVC, I know how you set the RequestMapping in every controller and method/action.

But what if I wanted this to be configurable, so for example I the following controllers:

BlogController 
 - with methods for listing blogs entries, single entry, new, update, etc.
ArticleController
 - with methods for listing articles entries, single entry, new, update, etc.

Now in my application, the administrator can setup 2 blogs for the webiste, and 1 article section so the urls would be like:

www.example.com/article_section1/ - uses ArticleController
www.example.com/blog1/ - uses BlogController
www.example.com/blog2/ - uses BlogController

Maybe after a while the administrator wants another article section, so they just configure that with a new section like:

www.example.com/article_section2/

This has to work dynamically/on-the-fly without having to restart the application of course.

My question is only concerned with how I will handle url mappings to my controllers.

How would this be possible with Spring MVC?

I only know how to map urls to controllers using @RequestMapping("/helloWorld") at the controller or method level, but this makes the url mappings fixed and not configurable like how I want it.

Update:

I will be storing the paths in the database, and with the mapping to the type of controller so like:

path                  controller
/article_section1/    article
/blog1/               blog
/blog2/               blog
..

With the above information, how could I dispatch the request to the correct controller?

Again, not looking to reload/redeploy, and I realize this will require more work but its in the spec :)

Edit
Report

1 Answer

2

Truly changing the request mappings at runtime might be hard (and not really recommended, since small errors can easily occur). If you still wish to do it, perhaps JRebel, and more specificly LiveRebel can be interesting for live redeployment of code and configuration.

Otherwise, like other posts suggested, RequestMappings supports wildcards, the limits of this should be clear after a quick read of the official documentation.

answered 2012-10-03T14:21:35.787

Your Answer