Java Spring3.1使用JSON休息:不工作

Java Spring3.1使用JSON休息:不工作,java,json,spring,rest,tomcat,Java,Json,Spring,Rest,Tomcat,一旦我将测试应用程序移动到一个高效的(?)应用程序并开始在Tomcat上测试,我基于Spring3.1的REST服务就停止工作了。虽然显示了默认的index.jsp,但我的应用程序(http://myhost:myport/test-无法访问webapp/myrestservice),并且我获取的请求资源(/test webapp/myrestservice)不可用 以下是我所做的: 控制器: package com.test.webapp.controller; import org.spr

一旦我将测试应用程序移动到一个高效的(?)应用程序并开始在Tomcat上测试,我基于Spring3.1的REST服务就停止工作了。虽然显示了默认的index.jsp,但我的应用程序(http://myhost:myport/test-无法访问webapp/myrestservice),并且我获取的请求资源(/test webapp/myrestservice)不可用

以下是我所做的:

控制器:

package com.test.webapp.controller;

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

import com.test.webap.entity.Account;

@Controller
@RequestMapping("/myrestservice")
public class AccountController{

@RequestMapping(method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Account getEntity() {
            // ... <simplified>
    return new Account(//...);
}
}
配置类:

package com.test.webapp.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan( basePackages = {"com.test.webapp.controller"})
public class AppConfig{
    // Nothing here. Once I start using the beans, I will put them here
}
而且,web.xml没有太多内容:


测试Web应用程序
在我的项目中没有别的东西。我错过什么了吗?以前的项目做的有点像记录传入的JSON请求等(现在已被删除)正在工作,但我不再有它了:(所以,有很多新手忧郁。请在这里帮助我。非常感谢

更新
问题已解决。请检查答案。

您是否尝试去Tomcat管理器查看部署了什么?它应该会显示已部署应用程序的列表。我认为路径已更改。

您在生产环境中使用的Tomcat版本是什么?看起来您需要Tomcat 7才能获得Servlet 3.0规范实现所需的d来支持您的WebApplicationInitializer。

因为您是Spring的新手,我建议您看看我以前的答案:


问题已解决。我觉得这是Servlet容器3.0的问题,可能是我的Tomcat 7配置中出现了问题。但是,我对
web.xml
做了一些小改动,现在可以正常工作了:


测试Web应用程序

显然,我必须明确地告诉Tomcat扫描ServletContainerInitializer的实现,并不是所有内容都是通过属性metadata complete=“false”

在web.xml中,我已经这样做了,并且我确实看到/测试了那里列出的webapp。显示默认的index.jsp,但结果是“请求的资源”(/test webapp/myrestservice)未找到“Tomcat7上出现错误。我使用的是Tomcat7.0.17。是的,在我以前的应用程序版本中,我使用了Spring3.0,web.xml有引导配置条目。但是,据我所知,使用Spring 3.1,我不需要在web.xml中进行此配置-它应该已经找到WebApplicationInitializer。我只记得我的web.xml是如何早期的,一个nd切换到它可以让这个应用程序工作。但是使用Spring 3.1,它不应该在web.xml中没有这么多配置的情况下工作吗?谢谢!谢谢Joel,我使用了你的Servlet3.0规范提示并找到了一种方法让它工作。谢谢。我在搜索stackoverflow以找到我问题的答案时,已经找到了你的答案。我添加了Springeclipse marketplace的IDE,我仍然无法解决我的问题。删除DOCTYPE,它是无效的-您告诉应用程序它是Servlet 2.3和3.0版本的应用程序。我在发布答案后立即意识到:-)感谢您的评论。
package com.test.webapp.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan( basePackages = {"com.test.webapp.controller"})
public class AppConfig{
    // Nothing here. Once I start using the beans, I will put them here
}