投稿

2フォロワー フォローする
0
Avatar

WARNING: No mapping found for HTTP request with URI

Hi Team,

I'm new in the Spring world and I'm building my first HelloWorld, but things are not working well, would someone help me?

This is my Login.java

package com.managementtool7ul.controller;

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

@Controller
public class Login {

@RequestMapping("/login")
public ModelAndView login() {
return new ModelAndView("index");
}
}

My managementtool7ul.xml

<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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.managementtool7ul.controller" />

<!-- <mvc:default-servlet-handler/> -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>

</beans>

My web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>CrunchifySpringMVCTutorial</display-name>
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>managementtool7ul</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>managementtool7ul</servlet-name>
<url-pattern>*.jsp</url-pattern>
<!--
<url-pattern>/index.jsp</url-pattern>
<url-pattern>/welcome.html</url-pattern>
<url-pattern>*.html</url-pattern>
-->
</servlet-mapping>
</web-app>

This is the log:

Jul 14, 2017 2:44:49 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/managementtool7ul/] in DispatcherServlet with name 'managementtool7ul'
Jul 14, 2017 2:45:07 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/managementtool7ul/welcome.jsp] in DispatcherServlet with name 'managementtool7ul'

The files structure:

Let me know if anything else is needed.

Leandro Takeda

ログインにログインしてコメントを残してください。

3件のコメント

1
Avatar

Quick question, is there a reason or requirement for using XML based configuration for Spring?  If you're new to Spring, I would highly recommend you start with Spring Boot.  It takes care of the basic setup and plumbing and ensures that it's correct, so you as a developer can just focus on writing your application.

If you absolutely need to continue with an XML based app, bump the log level to DEBUG for `org.springframework.web` and attach a complete set of application logs here.

Daniel Mikusa 1 票
0
Avatar

Hi Daniel, thanks for your comments. I fixed it, my web.xml was wrong.

I changed the URL pattern from: <url-pattern>*.jsp</url-pattern> to: <url-pattern>/</url-pattern> and it worked.

Also, I didn't want to use Spring Boot because, for me, that is starting, it looks like I will not see what really Spring works. I like to see how things works and not just see that works.

Thanks!

Leandro Takeda 0 票
0
Avatar

Good, yes it's important to get the DispatcherServlet setup as the default servlet.  Glad you were able to get it working!

I completely understand what you're doing as a learning exercise as well.  You're right, it's nice to build up as you're learning.  I would also suggest Spring Boot as a top-down learning tool.  It is essentially the accumulated knowledge from a lot of great engineers on how to wire up a Spring based application so it makes a really good example.

Taking a basic Spring Boot application and drilling down into the configuration that it sets up for you allows you to see how one would ideally setup a Spring app.  You can see what's happening by looking at the debug logs (set `--debug` flag) and the auto configuration output.  Using STS, you can also easily drill down to see how things work.  For example, you can command (Mac) / ctrl (Windows) click on an annotation like `@SpringBootApplication` to see how that enables AutoConfiguration & ComponentScan for you.  You can also go to Navigate -> Open Type... and enter `*AutoConfiguration` to easily find the various auto configuration classes which setup your app.  Ex: WebMvcAutoConfiguration will show you how web-mvc is configured.

Hope that helps!

Daniel Mikusa 0 票