[SPRING] Spring 3.1 MVC 애플리케이션의 HTTP 상태 404
SPRINGSpring 3.1 MVC 애플리케이션의 HTTP 상태 404
내가 만들고 간단하게 봄 3.1 mvc 웹 응용 프로그램을 실행하려고합니다 아래의 클래스를 사용하여 응답 본문에 단순히 "안녕하세요"반환하는 컨트롤러를 정의한 :
package com.jr.freedom.controllers;
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.ResponseBody;
@Controller
public class Hello {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
@ResponseBody
public String helloWorldInJson() {
return "hello";
}
}
이 URL을 시도했지만 404 오류가 계속 표시됩니까?
http : // localhost : 8080 / FreedomSpring / hello
다음은 내 서블릿입니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="mvc-config.xml" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<context:component-scan base-package="com.jr.freedom.controllers"></context:component-scan>
</beans>
다음은 web.xml 파일입니다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>FreedomSpring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FreedomSpring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
마지막으로 내 mvc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<mvc:annotation-driven />
<!-- the application context definition for the springapp DispatcherServlet -->
<mvc:view-controller path="/" view-name="index.jsp" />
</beans>
Windows 7 컴퓨터에서 바람둥이 7을 사용하고 있습니다. tomcat의 로그 파일에서 오류를 찾을 수 없습니다.
13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'FreedomSpring'
13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Shutting down log4j
13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Set web app root system property: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\FreedomSpring\]
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing log4j from [C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\FreedomSpring\WEB-INF\log4j.xml]
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'FreedomSpring'
0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring HTTP/1.1" 302 -
0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring/ HTTP/1.1" 404 997
0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:51 +0000] "GET /FreedomSpring/hello HTTP/1.1" 404 1012
어떤 아이디어?
해결법
-
==============================
1.DispatcherServlet이 * .htm에 매핑됩니다.
DispatcherServlet이 * .htm에 매핑됩니다.
<servlet-mapping> <servlet-name>FreedomSpring</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>
하지만 일치하지 않는 URL (http : // localhost : 8080 / FreedomSpring / hello)을 통해 컨트롤러에 액세스하고 있습니다. 세 가지 선택이 있습니다.
from https://stackoverflow.com/questions/9260777/http-status-404-on-spring-3-1-mvc-app by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] Spring을 사용하여 동일한 클래스를 주입 할 수 있습니까? (0) | 2019.04.30 |
---|---|
[SPRING] oauth2와 함께 스프링 클라우드 게이트웨이 사용 (0) | 2019.04.30 |
[SPRING] 참조하는 Java 프로젝트에서 정적 리소스 (WEB-INF) 폴더의 파일에 액세스하는 방법? (0) | 2019.04.30 |
[SPRING] Spring 데이터 JPA @OneToOne 주석 무한 재귀 오류 (0) | 2019.04.30 |
[SPRING] 단일 파일에 대한 Maven 리소스 필터링 (0) | 2019.04.30 |