Spring MVC application - URL gives No file found (404)
- by user1700184
I created a Spring-MVC project.
web.xml:
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/soundmails</url-pattern>
</servlet-mapping>
mvc-dispatcher-servlet.xml
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="somepkg.controllers" />
<bean id="multipartResolver" class="org.gmr.web.multipart.GMultipartResolver">
<property name="maxUploadSize" value="1048576" />
</bean>
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- property name="location">
<value>/WEB-INF/social.properties</value>
</property-->
</bean>
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter"/>
</list>
</property>
</bean>
</beans>
The controller has this code:
ProjectController.java
@Controller
@RequestMapping("/soundmails")
public class FileUploadController {
@RequestMapping(value="/test", method=RequestMethod.GET)
public @ResponseBody String test() {
System.out.println("Hai");
return "Hai";
}
}
I am using Google App Engine in my local machine to test this. I am getting these in my log:
[INFO] Oct 24, 2013 1:54:18 AM com.google.appengine.tools.development.LocalResourceFileServlet doGet
[INFO] WARNING: No file found for: /soundmails/test
I tried /soundmails/soundmails/test as well. That is also giving the same error.
I am using Spring 3.1.0.RELEASE
Can someone help me figure out what I am missing - /soundmails/test is giving 404 error.
Edit
I am unable to enable DEBUG logs for this. For some reason, it is not taking log level configured in logging.properties
But I observed something interesting:
1) If I map the request to empty string (value = "")
@RequestMapping(value="", method=RequestMethod.GET)
public @ResponseBody String test() {
System.out.println("Hai");
return "Hai";
}
Then, when I try to access 127.0.0.1/soundmails, it works fine (returns string "Hai").
2) When I have value="/test"
@RequestMapping(value="/test", method=RequestMethod.GET)
public @ResponseBody String test() {
System.out.println("Hai");
return "Hai";
}
and I try to access 127.0.0.1/soundmails/test, it is giving HTTP 404. This is weird.