ControllerClassNameHandlerMapping @Controller

这里也提到这个问题

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

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 magic sauce that makes this work as expected.

引用

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...






	<?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链接在这里
http://jira.springframework.org/browse/SPR-4129

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

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

http://code.google.com/p/nestorurquiza/wiki/SpringMVCTutorial

你可能感兴趣的:(spring,xml,Web,mvc,SVN)