Spring-Rest 应用程序中的 404 错误 [英] 404 error in Spring-Rest Application

查看:63
本文介绍了Spring-Rest 应用程序中的 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序显示rest+spring.but得到404错误:在运行时它应该给 jeresey+spring 作为输出网页xml文件

I have a simple application of displaying rest+spring.but getting 404 error: on run it should give jeresey+spring as output web xml file

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

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

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.spring.container.servlet.SpringServlet
        </servlet-class>
        <init-param>
            <param-name>
                                 com.sun.jersey.config.property.packages
                        </param-name>
            <param-value>com.mtv.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

应用上下文文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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.mtv.rest" />

        <bean id="transactionBo" 
                  class="com.mtv.rest.TransactionBoImpl" />

</beans>

支付类

package com.mtv.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mtv.rest.TransactionBo;

@Component
@Path("/payment")
public class PaymentService {

    @Autowired
    TransactionBo transactionBo;

    @GET
    @Path("/mtv")
    public Response savePayment() {

        String result = transactionBo.save();

        return Response.status(200).entity(result).build();

    }

}

界面是

package com.mtv.rest;

public class TransactionBoImpl implements TransactionBo {

    public String save() {

        return "Jersey + Spring example";

    }


}

有时tomcat端口也会出错.

also sometimes tomcat port gets error.

推荐答案

  • 正确检查您是否已正确添加所有JAR 文件/依赖项
  • 检查 applicationContext.xml 是否在适当的位置,即在 src 文件夹中.
  • 这是一些最常见的错误.

    This are some of the most common mistakes.

    这篇关于Spring-Rest 应用程序中的 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆