【发布时间】:2012-02-13 03:12:46
【问题描述】:
我正在使用 spring MVC 3.1 并测试不同的功能。我想验证以下来自@RequestMapping#value doc的声明
If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account for choosing between them
所以我创建了以下具有多个默认处理程序方法的控制器。
@Controller
@RequestMapping("/book")
public class BookController {
@RequestMapping
public @ResponseBody String greet() {
return "Hi Book!";
}
@RequestMapping
public @ResponseBody String meet() {
return "Nice to meet you Book!";
}
}
这是 Web 应用程序上下文配置
<beans ....>
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="com.botreeconsulting.lms.web"/>
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
但似乎我搞砸了,因为它在部署时给了我以下错误:
java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.meet()
to {[/book],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.greet() mapped.
现在的问题是这个控制器是否对文档中的内容进行建模?我觉得我没有正确理解它。请指导我对控制器进行建模以匹配有关多个默认处理程序的语句。
谢谢,阿米特
【问题讨论】:
标签: spring-mvc spring-3