0

很抱歉,这是我已经问过的另一个问题的重复问题:Spring MVC Rest: No mapping found for HTTP request with URI [/ecommerce-api/rest/checkout] in DispatcherServlet

但是我很生气,因为一段时间后问题又出现了。当一切似乎都突然工作时,它停止了:-(

我正在尝试使用 SpringMVC 构建 API,我正在使用 STS 3.3.0 进行开发并使用其余 shell 1.2.1 进行测试。

我发出的命令是:

获取电子商务 API/休息/结帐

我得到的错误是:

2013-09-10 11:56:49,614 调试 [tomcat-http--9] servlet.DispatcherServlet (DispatcherServlet.java:823) - 名称为 'api-dispatcher' 的 DispatcherServlet 处理 [/ecommerce-api/rest/ 的 GET 请求checkout] 2013-09-10 11:56:49,615 调试 [tomcat-http--9] handler.AbstractHandlerMethodMapping (AbstractHandlerMethodMapping.java:220) - 查找路径 /checkout 的处理程序方法 2013-09-10 11:56:49,615调试 [tomcat-http--9] handler.AbstractHandlerMethodMapping (AbstractHandlerMethodMapping.java:230) - 没有找到 [/checkout] 的处理程序方法 2013-09-10 11:56:49,615 WARN [tomcat-http--9] servlet .DispatcherServlet (DispatcherServlet.java:1108) - 在名为 'api-dispatcher' 的 DispatcherServlet 中找不到带有 URI [/ecommerce-api/rest/checkout] 的 HTTP 请求的映射 2013-09-10 11:56:49,615 DEBUG [tomcat-http--9] servlet.FrameworkServlet (FrameworkServlet.java:966) - 成功完成请求

直到昨天一切正常,今天早上我尝试向我真正基本的控制器添加更多功能,但出现上述错误。

我没有成功的尝试:

1) 从 git 存储库恢复到上一个​​工作版本

2)在干净的Tomcat安装中部署war包(尽量避免与Eclipse相关的任何可能的问题)

3) 从 STS 中的 vFabric 取消发布包 - 清理其工作目录 - 清理项目 - 再次部署它

我将我的 *.xml 和 java 文件复制到那里,即使它们似乎没问题,因为它们从几个小时前就开始工作了。

任何想法或建议将不胜感激。

一个沮丧的开发者(又名 Alexio)。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/application-context.xml
    </param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>api-dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/api-dispatcher-servlet.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>6</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>api-dispatcher</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>


</web-app>

api-dispatcher.xml

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

    <context:component-scan base-package="com.fashionis.api.ecommerce.controller" />
    <context:annotation-config />
    <mvc:annotation-driven />

    <import resource="classpath:/ecommerce-services-beans.xml"/>

</beans:beans>

结帐控制器.java

@Controller
@RequestMapping("/checkout")
public class CheckoutController {

    private static final Logger logger = LoggerFactory.getLogger(CheckoutController.class);

        @RequestMapping(method = RequestMethod.GET)
    public @ResponseBody
    Checkout getRandomCheckout() {

        logger.debug("Before instantiating checkoutManager");
        @SuppressWarnings("resource")
        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("ecommerce-services-beans.xml");
        CheckoutManager checkoutManager = ctx.getBean("checkoutManager", CheckoutManager.class);

        logger.debug("Before asking for checkout");

        Checkout checkout = checkoutManager
                .findById("514f2a8e20f7a78a1400001f");

        logger.debug("Checkout obtained. Con ID:" + checkout.getId());

        return checkout;
    }
}
4

0 回答 0