gpt4 book ai didi

java - RESTEasy-Spring 集成 web 应用程序抛出神秘错误 : NoResourceFoundFailure

转载 作者:行者123 更新时间:2023-12-01 16:03:56 24 4
gpt4 key购买 nike

我正在开发一个同时使用 Spring 框架和 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 模式之外的请求的详细信息。该异常对用户来说并不是致命的,但我认为它可能会破坏一些我不知道的东西。另外,日志中的异常从来都不是有趣的。如果您对此异常有任何见解,我将不胜感激!

最佳答案

答案来自订购问题。

我在 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>

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

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

<property name="order" value="0"/>

关于java - RESTEasy-Spring 集成 web 应用程序抛出神秘错误 : NoResourceFoundFailure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3105787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com