Andrea Dorigo
Andrea Dorigo

Reputation: 165

Java Spring MVC: No mapping found for HTTP request with URI

I've problems setting up Spring MVC... I've this project structure

-SpringTest<br />
   -Java Resources
      -src
         -org.basic.controller
             FormController.java
.
.
.
.
-WebContent
   +META-INF
   -WEB-INF
       dispatcher-servlet.xml
       +lib
       -views
           form.jsp
       web.xml

And these are the code pages:

web.xml

<web-app id="WebApp_ID" 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">

  <display-name>Spring Web MVC Application</display-name>

  <servlet>
    <servlet-name>dispatcher</servlet-name>
        <servlet-class>
                  org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

</web-app>

dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    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-2.5.xsd">



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

</beans>

FormController.java

package org.basic.controller;

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

@Controller
@RequestMapping("/form.html")
public class FormController {


}

But when, after a deploy with jboss, I try to access "/SpringTest/form.htm" it gives back this error:

WARN [org.springframework.web.servlet.PageNotFound] (http-localhost-127.0.0.1-8080-1) No mapping found for HTTP request with URI [/SpringTest/form.htm] in DispatcherServlet with name 'dispatcher'

Upvotes: 3

Views: 6353

Answers (2)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280138

@RequestMapping("/form.html")

vs

/SpringTest/form.htm

You have an extra l in your @RequestMapping url.

Don't forget to component-scan the package your controller is in.

Upvotes: 5

beinghuman
beinghuman

Reputation: 2146

I see you are not scanning the controller. Where is your context:component scan? Try adding it.

Also,why is your controller empty?Is it that you have not pasted code just to make it look clear in the Question or you haven't written anything in the Class? –

Upvotes: 2

Related Questions