Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Controller method order effects @RequestMapping behavior in ways not expected [SPR-5731] #10401

Closed
spring-projects-issues opened this issue May 8, 2009 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 8, 2009

Keith Donald opened SPR-5731 and commented

Works:

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {

	private AppointmentBook appointmentBook;
	
	@Autowired
	public AppointmentsController(AppointmentBook appointmentBook) {
		this.appointmentBook = appointmentBook;
	}

	@RequestMapping(value="/new", method = RequestMethod.GET)
	public AppointmentForm getNewForm() {
		return new AppointmentForm();
	}
	
	@RequestMapping(value="/{day}", method = RequestMethod.GET)
	public Appointments getForDay(@PathVariable Date day) {
		return appointmentBook.getAppointmentsForDay(day);
	}
	
}

Does not work:

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {

	private AppointmentBook appointmentBook;
	
	@Autowired
	public AppointmentsController(AppointmentBook appointmentBook) {
		this.appointmentBook = appointmentBook;
	}

	@RequestMapping(value="/{day}", method = RequestMethod.GET)
	public Appointments getForDay(@PathVariable Date day) {
		return appointmentBook.getAppointmentsForDay(day);
	}

	@RequestMapping(value="/new", method = RequestMethod.GET)
	public AppointmentForm getNewForm() {
		return new AppointmentForm();
	}
		
}

Specifically, a GET to /appointments/new results in:

java.lang.IllegalStateException: Could not find @PathVariable [day] in @RequestMapping
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.resolvePathVariable(AnnotationMethodHandlerAdapter.java:644)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolvePathVariable(HandlerMethodInvoker.java:514)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:262)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:146)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:355)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:343)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:763)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:614)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:526)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
	org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
	org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
	org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
	org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)

... indicating the {day} mapped method ran instead of the /new method. With the method order reversed, GET /appointments/new works as expected.


Affects: 3.0 M3

Issue Links:

Referenced from: commits 752832a

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

As a workaround, while I work on this, you can provide the full path in the @RequestMapping. I.e.

@RequestMapping("/appointments/new")
@RequestMapping("/appointments/{day}")

That works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants