3

我已经下载了Spring Webflow源,我想将 REST 通道(显示来自数据库的图像)添加到jsf-booking示例中。该通道在我的Spring-MVC示例应用程序中正常工作。

但是,我遇到了映射问题,因为在给定的地址上,JSF 处理程序正在响应错误消息,即 display.xhtml 文件不存在(并且 REST 侦听器应该处理该请求)。

这就是我注册处理程序的方式:

@Controller
@RequestMapping(value="/image")
public class ImageChannelImpl implements ImageChannel {

    @RequestMapping(value="/display.png", method=RequestMethod.GET)
    public void display(HttpServletResponse response) throws IOException {
(...)
        response.setContentType("image/png");
        ImageIO.write(img, "PNG", response.getOutputStream());
        response.getOutputStream().flush();     
        log.debug("display finished");
    }

}

我已经复制了处理程序映射;

<bean

    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <util:list id="beanList">
            <ref bean="stringHttpMessageConverter" />
            <ref bean="byteArrayHttpMessageConverter" />
        </util:list>
    </property>
</bean>

<bean id="stringHttpMessageConverter"
    class="org.springframework.http.converter.StringHttpMessageConverter" />

<bean id="byteArrayHttpMessageConverter"
    class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />

DispatcherServlet 正在监听 /spring/* 请求:

<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<!-- Map all /spring requests to the Dispatcher Servlet for handling -->
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/spring/*</url-pattern>
</servlet-mapping>

因此,我预计图像将在地址 /spring/image/display.png 上可用,但 REST 处理程序没有接受该请求,也没有处理 /image/display.png 。

那么,必须在该配置中进行哪些更改才能注册 REST 通道?我试图谷歌任何示例或文档,如何配置 Spring WebFlow 和 Spring MVC 通道,但我没有找到任何东西。

4

1 回答 1

1

您应该为 FlowHandlerMapping 定义“默认处理程序”:

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry"/>
    <property name="order" value="0"/>
    <!--If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" --> 
    <property name="defaultHandler" ref="requestMappingHandlerMapping"/>
</bean>

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" id="requestMappingHandlerMapping">
    <property name="order" value="1"/>
</bean>

您可以根据您的 Spring MVC 版本将 RequestMappingHandlerMapping 替换为 AnnotationMethodHandlerAdapter(RequestMappingHandlerMapping 是最新 SMVC 版本中的首选方式)

于 2013-01-22T16:22:48.603 回答