복붙노트

[SPRING] @RequestMapping이 올바르게 매핑되지 않았습니다.

SPRING

@RequestMapping이 올바르게 매핑되지 않았습니다.

컨트롤러를 설치하려고하는데 불행히도 출력을 볼 수 없습니다 ... 모든 것이 올바르게 렌더링됩니다. 내가 http : // localhost : 8080 / CMT / content / edit로 갈 때 나는 404 페이지를 얻는다. Netbeans에서 내 앱을 실행하면 http : // localhost : 8080 / CMT로 이동합니다.

package com.cmt.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class Content {

    @RequestMapping(value="/content/edit", method=RequestMethod.GET)
    public ModelAndView edit(Model model) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }
}

app-config.xml

<?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"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="com.cmt" />
    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />
    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

을 포함한다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

어떻게 디버깅하여 작동하고 무엇이 작동하지 않는지 볼 수 있습니까?

최신 정보

Netbeans의 GlassFish 서버 로그인 정보

INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1531ed: defining beans [content,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@b91162
INFO: Mapped URL path [/content/edit] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit.*] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit/] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: FrameworkServlet 'Spring-MVC-Dispatcher-Servlet': initialization completed in 1234 ms
INFO: WEB0671: Loading application [CMT] at [/CMT]
INFO: CMT was successfully deployed in 3,725 milliseconds.

해결법

  1. ==============================

    1.DispatcherServlet이라는 app가 web.xml의 / *에 매핑되어 있습니까? 이전 질문에서 볼 수 있습니다.

    DispatcherServlet이라는 app가 web.xml의 / *에 매핑되어 있습니까? 이전 질문에서 볼 수 있습니다.

    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    

    / content / edit URL이 * .htm 패턴과 일치하지 않습니다. 가능한 해결 방법은 /content/edit.htm을 시도하십시오.

  2. from https://stackoverflow.com/questions/9690628/requestmapping-not-mapping-correctly by cc-by-sa and MIT license