dimanche 5 avril 2015

Spring mvc return http 404 with tomcat 7 servlet 3.0 and java 7


Vote count:

0




I'm trying to config a java web project with spring mvc, and finally it will be upload to AWS. The environment is tomcat 7, servlet 3.0, java 7 with latest spring mvc 4.1.6


I followed a book called beginning spring from wrox press.


web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP
http://ift.tt/1eWqHMP"
version="3.0">
<servlet>
<servlet-name>mathschool</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mathschool</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


mathschool-servlet.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1cnl1uo
http://ift.tt/GArMu7
http://ift.tt/1ldEMZY">

<context:component-scan base-package="sg.mathschool.controller" />
<context:annotation-config />

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


pom.xml



<project
xmlns="http://ift.tt/IH78KX"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/IH78KX
http://ift.tt/VE5zRx">

<modelVersion>4.0.0</modelVersion>
<groupId>MathSchool</groupId>
<artifactId>MathSchool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.28.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>


HomeController



package sg.mathschool.controller;

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

@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
}


Project structure


enter image description here


enter image description here


enter image description here


enter image description here


enter image description here


However, I get this 404 always, I thought this is just a basic configuration to get a hello world application. What is wrong, and how can I get http://localhost:8080/ instead of http://localhost:8080/MathSchool/



asked 52 secs ago







Spring mvc return http 404 with tomcat 7 servlet 3.0 and java 7

Aucun commentaire:

Enregistrer un commentaire