【发布时间】:2011-01-15 08:57:34
【问题描述】:
我有一个简单的 spring 3 mvc 应用程序,当有人浏览到 http://localhost:8080/ 时它只会输出 index.aspx
当我执行 RunAs 并在服务器选项上运行时(与 tomcat 6 挂钩),它会打开浏览器到 http://localhost:8080/springmvc2/(其中 springmvc2 是应用程序名称)。
我已经使用 netbeans 构建了同样的简单测试应用程序,使用 url http://localhost:8080/ 可以正常工作
我的 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>Springmvc2</display-name>
<description>Springmvc2 web application</description>
<servlet>
<servlet-name>Springmvc2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Maps all /app requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Springmvc2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
而我的 HomeController 是:
package com.springmvc2.web;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
@Controller
public class HomeController {
@RequestMapping("/")
public String Index(){
return "index";
}
@RequestMapping("/test")
public String Index2(){
return "index";
}
}
你可以在这里查看我的 pom.xml 文件:Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?
这也是生成的目标文件夹:
/target
/target/springmvc2/meta-inf
/target/springmvc2/web-inf
/target/springmvc2/test.html
/target/war/springmvc2.war
/target/pom.xml
我创建 test.html 只是为了看看是否至少可以渲染,但 http://localhost:8080/test.html 不起作用,http://localhost:8080/springvc2/test.html 也不起作用。
我收到 404 错误,所以我猜它没有正确部署到 tomcat,尤其是因为 test.html 文件甚至没有呈现。
但也许 test.html 没有呈现,因为我的 springmvc2-servlet.xml 中有这个:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" p:order="2"/>
我不得不承认,Java 开发充斥着配置问题,尤其是对于新手来说!!
更新
编译并执行 runas 服务,打开浏览器,我从 tomcat 收到此消息:
WARNING: No mapping found for HTTP request with URI [/springmvc2/] in DispatcherServlet with name 'springmvc2'
【问题讨论】:
标签: java spring tomcat maven-2 spring-mvc