0

我正在开发一个同时使用 Spring Framework 和 RESTEasy 的 web 应用程序。该应用程序已配置为发送 REST 请求有一段时间了,但我最近将其设置为也接收 REST 请求。我适当地配置了我的 web.xml,并且应用程序已经毫无问题地接收并处理了 REST 请求

这是一个 web.xml 片段,详细说明了 REST 设置:

<listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.spring.SpringContextLoaderListener
    </listener-class>
</listener>

...

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/AutomatedProcessing/rest/*</url-pattern>
</servlet-mapping>

但是,当我在浏览器中浏览应用程序时,我不断在日志中看到这些异常:

    org.jboss.resteasy.springmvc.ResteasyHandlerMapping - Resource Not Found: Could not find resource for relative :
org.jboss.resteasy.spi.NoResourceFoundFailure: Could not find resource for relative : /AccountManagement/login.do of full path: https://dev.produceredge.com:7002/AccountManagement/login.do

在我看来,REST 突然尝试处理所有请求,而不仅仅是匹配 /AutomatedProcessing/rest/* URL 模式的请求。 我没有找到有关NoResourceFoundFailure异常的详细信息,或者 REST 为何会尝试处理其分配的 URL 模式之外的请求。该异常对用户来说不是致命的,但我认为它可能会破坏我不知道的东西。另外,日志中的异常永远不会有趣。我将不胜感激有关此异常的任何见解!

4

1 回答 1

1

答案来自订购问题。

我在 config.xml 文件中设置了另一个 UrlHandlerMapping:

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="openPersistenceManagerInView"/>
            </list>
        </property>
        <property name="mappings">
            <value>
                **/AccountManagement/login.do=flowController
                **/AccountManagement/createAccount.do=flowController
                **/AccountManagement/manageAccount.do=flowController
            </value>
        </property>
        <property name="alwaysUseFullPath" value="true"/>
    </bean>

此映射没有“订单”属性,这意味着订单被设置为默认值。在 JBoss 包含的 sprincmvc-resteasy.xml 文件中可以找到处理映射 RESTEasy 资源的 ResteasyHandlerMapping。这个映射也没有“order”属性。这导致两个映射具有相同的排序优先级,并且由于 RESTEasy 映射首先出现在 XML 中,它试图处理所有请求。

解决方案:将此属性添加到您的默认 url 映射器:

<property name="order" value="0"/>
于 2010-06-30T20:15:33.097 回答