我的带有"/"映射的控制器/ servlet不会覆盖"Hello App Engine!"

Dav*_*ave 1 google-app-engine web.xml servlets spring-mvc sts-springsourcetoolsuite

我正在谷歌应用程序引擎上使用Spring MVC,尽管我已经得到了一个基本的hello world示例,但是当我使用"/"的请求映射时,我无法显示我的servlet.即使我在控制器中指定"/"作为我的请求映射,我仍然会收到"Hello App Engine!" 带有我项目链接的页面.我已经从我的web xml中取出了welcome-file声明.

基本上...

package my.package.for.spring.stuff.controllers;

import ....;

// It doesn't seem to make a difference if 
// I have this reqeustmapping or not...
@Controller
public class MainController {

  // If I change mapping to "/main" and then go to
  // localhost:8888/main then everything works as expected
  @RequestMapping("/")
  public String HelloWorld() {
    return "MyView";
  }
}
Run Code Online (Sandbox Code Playgroud)

仍然会去"Hello App Engine!" 页.另外,这是我的web.xml ...

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">


    <servlet>
        <servlet-name>SpringAppEngine</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringAppEngine</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

然后这是我的春天xml ...

<?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:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <context:component-scan base-package="my.package.for.spring.stuff" />

        <bean id="viewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                p:prefix="/WEB-INF/views/main/" p:suffix=".jsp" />

</beans>
Run Code Online (Sandbox Code Playgroud)

为什么即使我在控制器中声明根映射,应用程序引擎生成的欢迎文件仍然显示?我知道我的设置应该是正确的,因为当我更改请求映射时,一切都按预期工作.

JB *_*zet 8

servlet 3.0规范说:

仅包含'/'字符的字符串表示应用程序的"默认"servlet.

它还说:

默认情况下,所有应用程序都将在welcome-file-list列表中包含index.htm(l)和index.jsp.描述符可用于覆盖这些默认设置.

所以,我猜这个容器认为隐式的index.html欢迎文件是完全匹配的,它优先于映射到的默认servlet /.

解决方案是删除index.html文件,或者可能是在描述符中定义显式空欢迎文件列表.