2015-03-03 3 views
1

Я пытаюсь создать веб-сайт весны mvc в Google App Engine. Но я не могу сделать работу маршрутизации/картографии.Spring MVC routing в Google App Engine

У меня есть HelloController, который указывает на то, что я хочу, чтобы отобразить в /hello

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

@Controller 
@RequestMapping("/hello") 
public class HelloController { 

    @RequestMapping(method = RequestMethod.GET) 
    public String Index() { 
     return "hello"; 
    } 
} 

и очень простой hello.jsp файл

<html> 
    <head><title>Hello :: Spring Application</title></head> 
    <body> 
    <h1>Hello - Spring Application</h1> 
    <p>Greetings.</p> 
    </body> 
</html> 

Однако, когда я пытаюсь получить доступ к /hello, я буду получать 404 Не Найдено.

вот мой XML-файл отображения mvc-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     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 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="com.example.web" /> 
    <mvc:annotation-driven /> 

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 
</beans> 

Что мне не хватает? Как это исправить?

+0

вы карта пружинного сервлета в web.xml? –

+0

где вы положили hello.jsp? Я полагаю, вы должны поместить его в каталог, указанный 'prefix' в' InternalResourceViewResolver' config – hsluo

ответ

2

У вас есть web.xml?

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

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Processes application requests --> 
<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/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

ContextLoaderListener привязывает жизненный цикл ApplicationContext к ServletContext жизненного цикла и автоматизировать создание ApplicationContext. ApplicationContext - это место для весенних бобах , и мы можем предоставить его конфигурацию через contextConfigLocation контекстный параметр. Файл root-context.xml предоставляет конфигурацию для WebApplicationContext.

Ее эйс обучающей http://www.journaldev.com/2433/spring-mvc-tutorial-for-beginners-with-spring-tool-suite