Spring 3.1 REST с JSON :Не работает

Как только я переместил свое тестовое приложение в продуктивное (? )и начал тестирование на Tomcat, мои службы REST на основе Spring 3.1 перестали работать. Хотя отображается 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(//...);
}
}

Конфигурация Dispatch Servlet:

package com.test.webapp.web;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;   
import com.test.webapp.config.AppConfig;

public class AppInit implements WebApplicationInitializer {

    private static final String DISPATCHER_SERVLET_NAME = "dispatcher";

    public void onStartup(ServletContext container) throws ServletException {
        // Create the dispatcher servlet's Spring application context
        AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
        dispatcherContext.register(AppConfig.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(dispatcherContext));

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher = container.addServlet(
                DISPATCHER_SERVLET_NAME, new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

    }
}

Класс конфигурации:

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 не так уж много:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Test Web App</display-name>
</web-app>

В моем проекте нет ничего, кроме этого. Я что-то упускаю? Старый проект, который немного больше походил на регистрацию входящих запросов JSON и т. д. (, который сейчас был удален ), работал, но у меня его больше нет :(Итак, много хандры для новичков.Пожалуйста, помогите мне здесь. Большое спасибо!!

Обновление Проблема решена. Проверьте ответ

5
задан Betlista 26 September 2012 в 13:18
поделиться