복붙노트

[SPRING] 스프링 MVC 매핑 문제

SPRING

스프링 MVC 매핑 문제

나는 단순한 스프링 MVC 애플리케이션이라고 생각했다. 그러나 requestMappings을 올바르게 설정하는 것처럼 보일 수 있습니다. 이상한 점은 로그에 URL이 적절한 컨트롤러에 매핑되어 있지만 Dispatcher가 런타임에 찾을 수없는 것임을 보여주는 것입니다. 어떤 제안이라도 많이 부탁드립니다.

로그

INFO: Mapped URL path [/app/index] onto handler     [com.noisyair.whatisayis.web.MainController@420a52f]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/app/index.*] onto handler [com.noisyair.whatisayis.web.MainController@420a52f]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/app/index/] onto handler [com.noisyair.whatisayis.web.MainController@420a52f]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/app/tags/{tag}] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/app/tags/{tag}.*] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/app/tags/{tag}/] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6]
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'wisi': initialization completed in 237 ms
Jan 11, 2010 2:14:21 PM org.apache.catalina.core.StandardContext start
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/] has already been started
Jan 11, 2010 2:14:41 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/app/index] in DispatcherServlet with name 'wisi'

Web.xml 파일

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- The Spring MVC framework handles all of this stuff.  Just pass it along -->
<servlet>
    <servlet-name>wisi</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>wisi</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

컨트롤러 클래스 :

@Controller
public class MainController {

@Autowired
private LearningEntryService learningEntryService;

public LearningEntryService getLearningEntryService() {
    return learningEntryService;
}

public void setLearningEntryService(LearningEntryService learningEntryService) {
    this.learningEntryService = learningEntryService;
}

@RequestMapping(value = "/app/index", method = RequestMethod.GET)
public ModelAndView sayHello(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    Map<String, Object> model = new HashMap<String, Object>();
    List<LearningEntry> le = learningEntryService.getLearningEntries();
    model.put("learningEntries", le);
    return new ModelAndView("main", model);
}
}

해결법

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

    1.@RequestMapping과 모두에서 "/ app"를 복제하면 안됩니다. 즉 sayHello가 이제 "/ app / app / index"에 매핑됩니다. 당신은 쓸 수 있습니다

    @RequestMapping과 모두에서 "/ app"를 복제하면 안됩니다. 즉 sayHello가 이제 "/ app / app / index"에 매핑됩니다. 당신은 쓸 수 있습니다

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    

    (또는 DefaultAnnotationHandlerMapping Bean을 설정에 선언하고 allwaysUseFullPath 속성을 true로 설정하여 기본 동작을 재정의 할 수 있습니다)

  2. from https://stackoverflow.com/questions/2045384/spring-mvc-mapping-problem by cc-by-sa and MIT license