我是Spring MVC的新手。我正在尝试使用Spring MVC和Tomcat作为服务器来创建一个简单的Web应用程序。但是当我部署我的项目时,我得到错误404没有找到。 你能帮我吗? 这里是我的web.xml在tomcat上未找到404的Spring MVC
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-web-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/main/index</welcome-file>
</welcome-file-list>
</web-app>
这里是我的控制器:
@Controller
@RequestMapping(value = "/main")
public class RootController {
@RequestMapping(value = "/index")
public String printHello(){
return "index";
}
}
这里是我的春天网络servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:component-scan base-package="com.controllers" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:annotation-driven />
</beans>
您可以在启动服务器后访问tomcat服务器页面吗?通常'http:// localhost:8080 /'如果可以去管理器应用程序,看到你的应用程序在那里列出。 –
@ Rajith Pemabandu,不,我不能在那里看到我的应用程序,我什么都没有得到http:// localhost:8080/ – Rostyk
如果你只是想让Spring MVC web应用程序快速启动并运行,你是否考虑过Spring Boot?您可以从start.spring.io快速建立项目。如果不是,你可以发布tomcat日志。 –