1

My main controller serves the public user. It has the following mappings:

@Controller
@RequestMapping(value="/") 
public class HomeController extends BaseController {

@RequestMapping("/") // handles www.somesite.com
public ModelAndView request(Model model) {

@RequestMapping("/{contentId}")  // handles www.somesite.com/sports
public ModelAndView requestWithContentId(@PathVariable String contentId, Model model) {

@RequestMapping("/{contentId}/**") // handles www.somesite.com/sports/hockey/nhl , etc
public ModelAndView requestWithContentId2(@PathVariable String contentId, Model model) {

I also have a set of admin controllers that map to paths matching /admin*. Here's one example:

@Controller
@RequestMapping(value="/admin/article")
public class AdminArticleController extends BaseController
  1. I find that my main controller mappings are of higher priority. Consequently, request for /admin/article is processed by the main controller and not by dedicated AdminArticleController. How can I fix this?

  2. I also notice that requests for style sheet sitting in /static/default.css, also go through the main controller. Is there a way to avoid this?

jacekn
  • 1,521
  • 5
  • 29
  • 50

1 Answers1

2

Change your URL scheme. Starting your URLs with a variable in Spring MVC is pretty bad, for the reason you have just demonstrated.

Either change your content-links to something like /content/{contentId} or create explicit mappings for all content, i.e. /sports, /whatever...

As a last resort, if you absolutely can't change how your URL scheme looks to your users, use something like Tuckey urlrewrite and do a re-write:

/xyz -> /content/xyz

EXCEPT for "known" context like "admin" or "static".

pap
  • 27,064
  • 6
  • 41
  • 46
  • I sort of came to the same conclusions about what you call /content, except I thought more in line of /public. Nevertheless, this fails miserably with my existing admin mappings. Maybe there are ways to reconfigure all mappings to work with this. I'll send you my war if you wish. But even if you go through that effort, suggesting that one cannot have Spring handle simple www.somesite.com/sports/nhl url means that spring is retarded, even more than I thought. – jacekn May 04 '12 at 02:58
  • I posted a question on alternatives to Spring on this issue and some admin closed it. :) http://stackoverflow.com/questions/10424825/spring-3-controller-mapping-conflicts – jacekn May 04 '12 at 03:31
  • The alternative question is here: http://stackoverflow.com/questions/10442260/java-php-domino-something-else . Not sure why some kid jumped on closing. There is no spring solution in sight, so question is valid. – jacekn May 04 '12 at 03:40
  • @jacekn well, no framework can support all possible use-cases. That doesn't make them retarded, just limited. And I suggested to you a common way to get around it, but as you stated in your "alternative" question, "Url rewriting is just not sitting with me". If you're going to reject solutions based on irrational reasons or "gut feelings" then I don't think I can help you further. – pap May 04 '12 at 07:27
  • They are very rational feelings. Irrational to me is to base the project on a framework that promotes itself as friendly url handler and then to use url rewriting to make things work. Neither of the options you have provided answer the very question asked directly. However, you reinforced my view that I need to stop betting on Spring and look at something better. Thanks for your input. – jacekn May 04 '12 at 11:20