Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 5.17 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HTTP Status 404 on Spring 3.1 MVC app
  2. package com.jr.freedom.controllers;
  3.  
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.ResponseBody;
  8.  
  9. @Controller
  10. public class Hello {
  11.  
  12.     @RequestMapping(value = "/hello", method = RequestMethod.GET)
  13.     @ResponseBody
  14.     public String helloWorldInJson() {
  15.  
  16.         return "hello";
  17.     }
  18. }
  19.        
  20. <?xml version="1.0" encoding="UTF-8"?>
  21. <beans xmlns="http://www.springframework.org/schema/beans"
  22.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  23.     xsi:schemaLocation="
  24.         http://www.springframework.org/schema/beans      
  25.         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  26.         http://www.springframework.org/schema/context
  27.         http://www.springframework.org/schema/context/spring-context-3.1.xsd">
  28.  
  29.     <import resource="mvc-config.xml" />
  30.  
  31.     <bean
  32.         class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
  33.  
  34.     <!-- Resolves views selected for rendering by @Controllers to .jsp resources
  35.         in the /WEB-INF/views directory -->
  36.     <bean id="viewResolver"
  37.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  38.         <property name="prefix" value="/WEB-INF/views/" />
  39.         <property name="suffix" value=".jsp" />
  40.     </bean>
  41.  
  42.     <bean
  43.         class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
  44.  
  45.     <context:component-scan base-package="com.jr.freedom.controllers"></context:component-scan>
  46.  
  47.  
  48. </beans>
  49.        
  50. <?xml version="1.0" encoding="UTF-8"?>
  51.  
  52. <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  53.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  55.          http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  56.  
  57.     <servlet>
  58.         <servlet-name>FreedomSpring</servlet-name>
  59.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  60.         <load-on-startup>1</load-on-startup>
  61.     </servlet>
  62.  
  63.     <servlet-mapping>
  64.         <servlet-name>FreedomSpring</servlet-name>
  65.         <url-pattern>*.htm</url-pattern>
  66.     </servlet-mapping>
  67.  
  68.  
  69.     <listener>
  70.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  71.     </listener>
  72.  
  73.     <context-param>
  74.         <param-name>contextConfigLocation</param-name>
  75.         <param-value>
  76.  
  77.         </param-value>
  78.     </context-param>
  79.  
  80.     <context-param>
  81.         <param-name>log4jConfigLocation</param-name>
  82.         <param-value>/WEB-INF/log4j.xml</param-value>
  83.     </context-param>
  84.  
  85.     <welcome-file-list>
  86.         <welcome-file>
  87.       index.jsp
  88.     </welcome-file>
  89.     </welcome-file-list>
  90.  
  91.     <listener>
  92.         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  93.     </listener>
  94.  
  95. </web-app>
  96.        
  97. <?xml version="1.0" encoding="UTF-8"?>
  98. <beans xmlns="http://www.springframework.org/schema/beans"
  99.     xmlns:mvc="http://www.springframework.org/schema/mvc"
  100.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101.     xsi:schemaLocation="
  102.         http://www.springframework.org/schema/beans
  103.         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  104.         http://www.springframework.org/schema/mvc
  105.         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
  106.  
  107.     <mvc:annotation-driven />
  108.  
  109.     <!-- the application context definition for the springapp DispatcherServlet -->
  110.  
  111.  
  112.     <mvc:view-controller path="/" view-name="index.jsp" />
  113.  
  114.  
  115. </beans>
  116.        
  117. 13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
  118. INFO: Destroying Spring FrameworkServlet 'FreedomSpring'
  119. 13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
  120. INFO: Shutting down log4j
  121. 13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
  122. INFO: Closing Spring root WebApplicationContext
  123. 13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
  124. INFO: Initializing Spring root WebApplicationContext
  125. 13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
  126. INFO: Set web app root system property: 'webapp.root' = [C:Program FilesApache Software FoundationTomcat 7.0webappsFreedomSpring]
  127. 13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
  128. INFO: Initializing log4j from [C:Program FilesApache Software FoundationTomcat 7.0webappsFreedomSpringWEB-INFlog4j.xml]
  129. 13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
  130. INFO: Initializing Spring FrameworkServlet 'FreedomSpring'
  131.  
  132.  
  133. 0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring HTTP/1.1" 302 -
  134. 0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring/ HTTP/1.1" 404 997
  135. 0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:51 +0000] "GET /FreedomSpring/hello HTTP/1.1" 404 1012
  136.        
  137. <servlet-mapping>
  138.     <servlet-name>FreedomSpring</servlet-name>
  139.     <url-pattern>*.htm</url-pattern>
  140. </servlet-mapping>
  141.        
  142. <servlet-mapping>
  143.     <servlet-name>FreedomSpring</servlet-name>
  144.     <url-pattern>/*</url-pattern>
  145. </servlet-mapping>
  146.        
  147. <url-pattern>/*.htm</url-pattern>
  148.        
  149. <url-pattern>/mvc/*</url-pattern>