ControllerClassNameHandlerMapping @Controller

这里也提到这个问题

[url]http://forum.springsource.org/showthread.php?p=151750[/url]

Allow ControllerClassNameHandlerMapping and @Controller to work together

似乎在Spring mvc 2.5.4里面有一个 bug


就是当你实现一个controller 时候,使用 COC原则自动映射。无法映射到对应的默认方法 handleRequestInternal


这个问题在 spring 官方论坛的mvc版块里面也提到了这个问题。还是 appfuse Matt Raible 提交的。


具体的一个解决方式是 Keith Donald 提出的。看看他的配置文件就知道了。


Matt Raible 看了以后说


Thanks Keith - your webmvc-config.xml seems to contain the [b]magic sauce[/b] that makes this work as expected.

[quote]
Keith Donald added a comment - 14/Apr/08 12:27 PM
In Matt's example the index method on HomeController would be mapped to the URL /home/index by the 2.5.3 convention, which I imagine isn't what he wants.
Just to provide more usage examples of this feature, here is an example in the Spring MVC + Web Flow reference application "booking-mvc". You can see the code on-line here: https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc

Specifically see:

@Controller code: https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java

Config:
https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml

The URls mapped by convention are then:

/hotels/index
/hotels/search
/hotels/show
/hotels/deleteBooking

But no, /hotels doesn't mapped to to the index method by default... not in 2.5.3 anyway. Is this the convention you want? Perhaps we could employ a convention to map the root controller URL e.g. /home to a "home" method on the HomeController...


[/quote]



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="0" />
<property name="flowRegistry" ref="flowRegistry" />
</bean>

<!-- Maps request paths to @Controller classes; e.g. a path of /hotels looks for a controller named HotelsController -->
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="order" value="1" />
<property name="defaultHandler">
<!-- If no @Controller match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
</bean>

<!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
</bean>

<!-- Configures the Tiles layout system -->
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/layouts/layouts.xml</value>
<value>/WEB-INF/views.xml</value>
<value>/WEB-INF/hotels/views.xml</value>
<value>/WEB-INF/hotels/booking/views.xml</value>
</list>
</property>
</bean>

<!-- Dispatches requests mapped to POJO @Controllers implementations -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>

<!-- Custom FlowHandler for the hotel booking flow -->
<bean name="hotels/booking" class="org.springframework.webflow.samples.booking.BookingFlowHandler" />

</beans>



提交到JIRA链接在这里
[url]http://jira.springframework.org/browse/SPR-4129[/url]

下面2个spring mvc 相关的链接可以看看

[url]http://blog.springsource.com/2007/11/14/annotated-web-mvc-controllers-in-spring-25/[/url]

[url]http://code.google.com/p/nestorurquiza/wiki/SpringMVCTutorial[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值