Issue 1:
Florian Rampp opened SPR-7288 and commented

In the given forum entry, I outline a use case for splitting the handling of a REST resource between several controllers. While, e.g. the methods PUT and DELETE on a resource describe the setup and teardown of some kind of bucket, the POST to the same URL creates new content in the bucket. These two kinds of functionality are very different and thus may have two different business service interfaces. Therefore a split in the controller to reflect this distinction would be reasonable.

I would propose to consider, whether the rule that one resource can only handled by a single controller should be extended to include the HTTP method, so that different HTTP methods of the same resource can be handled in different controllers.

Reference URL: http://forum.springsource.org/showthread.php?t=90822

Issue 2:
Mark Hopkins opened SPR-6822 and commented

Given the following:

@Controller
public class Controller1 {
@RequestMapping(value="/someurl", method=GET)
public String doGet() {
return "view";
}
}

@Controller
public class Controller2 {
@RequestMapping(value="/someurl", method=POST)
public String doPost() {
// do something different for posts
return "view";
}
}

....
<context:spring-configured/>
<context:annotation-config/>
<context:component-scan base-package="..."/>
<context:component-scan base-package="..."/>
....

you get the following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/web-application-config.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot map handler [controller2] to URL path [/someurl]: There is already handler [Controller1@1830ec7] mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
...

In our specific domain it makes most sense to have the GET and POST for the same URL split over two different classes.

Affects: 3.0 GA

2 votes, 3 watchers