Java Servlet Spring+;jax-rs服务

Java Servlet Spring+;jax-rs服务,java,web-services,spring,spring-mvc,jax-rs,Java,Web Services,Spring,Spring Mvc,Jax Rs,我是spring services的新手,我正在尝试创建一个简单的Web服务示例,返回字符串Hello world。我的代码配置是: myServletName org.springframework.web.servlet.DispatcherServlet 上下文类 org.springframework.web.context.support.AnnotationConfigWebApplicationContext 上下文配置位置 com.MyPackageDirectionWebSe

我是spring services的新手,我正在尝试创建一个简单的Web服务示例,返回字符串Hello world。我的代码配置是:


myServletName
org.springframework.web.servlet.DispatcherServlet
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
com.MyPackageDirectionWebServices.remoting
MyServletName
/休息/*
HelloWs.java

package com.MyPackageDirectionWebServices.remoting;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller

@RequestMapping("/hello")

public class HelloWs {
    @RequestMapping(value= "helloWorld", method = RequestMethod.GET)
    @ResponseBody

    public String HelloWorld() {
        return "Hello World";
    }
在我的AppContext-Remoting.xml中,我添加了follow-anotion


但当我启动应用程序并转到服务时:

localhost:8080/MyAppname/rest/hello/helloWorld
我得到HTTP 404,并在Eclipse控制台中发现此错误:

警告:org.springframework.web.servlet.PageNotFound-在名为“MyServletName”的DispatcherServlet中找不到URI为[/MyAppname/rest/hello/helloWorld]的HTTP请求的映射


有人能帮我拿这个吗?太多了

Toni,您需要在contextConfigLocation中提到spring配置xml文件名,如下所示(根据需要更改路径)


appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/AppContext-Remoting.xml

如果您有java配置(而不是xml文件),您可以以不同的方式使用contextClass和contextConfigLocation

尝试添加斜杠:
@value='/hellohorld'
。谢谢,但我尝试了斜杠,结果是一样的。还有一些想法吗?Spring识别clases@controller,因为控制台说:您在哪里提到“AppContext Remoting.xml”是您的配置文件?它是src/main/resources中Spring的配置文件。我不确定是否必须在我的WEBINF文件夹下创建一个servlet.xml,并在servlet上提及它?对吗?
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/AppContext-Remoting.xml</param-value>
    </init-param>
</servlet>