java - Two Spring Controllers matching to the same URL result in wrong controller call -



java - Two Spring Controllers matching to the same URL result in wrong controller call -

we have problem 2 spring controllers happen interfere each other. 1 controller matches via wildcard-prefix url suffix. controller matches url prefix. expect urls read left right, seems not case.

consider next code (edited):

@requestmapping(value = "/**/abcdefg") public class controller1 {...} @requestmapping(value = "/**/xyz") public class controller2 {...} @requestmapping(value = "/some/{path}") public class controller3 { @requestmapping(value = "/{page}", method = requestmethod.get) public string page(@pathvariable("page") final string page, final model model) { //do sth } }

the problem now, if url "/some/path/abcdefg" called, controller1 kicks in. want controller3.

unfortunately behavior not same other controllers!

if url "/some/path/xyz" called, controller3 kicks in. behavior reproducable controllers. behaves same , controller not randomly chosen.

the spring documentation questions other users point idea, "first" controller taken, matches given pattern. however, not create quite sense me, since controller1 , 2 have very similar requestmapping , yet controllers match differently!

everything handled dispatcher servlet.

does have hint may happening?

this part i expect urls read left right, seems not case. , you're right, not case. mappings resolved specificity, relevant piece of doc available here

a pattern lower count of uri variables , wild cards considered more specific. illustration /hotels/{hotel}/* has 1 uri variable , 1 wild card , considered more specific /hotels/{hotel}/** 1 uri variable , 2 wild cards.

if 2 patterns have same count, 1 longer considered more specific. illustration /foo/bar* longer , considered more specific /foo/*.

when 2 patterns have same count , length, pattern fewer wild cards considered more specific. illustration /hotels/{hotel} more specific /hotels/*.

if 2 mappings match request, more specific apply. work out mappings follow specificity rules, based on requirements

java spring spring-mvc controller

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -