Ad

No Mapping Found For HTTP Request With URI [/HorarioLivre/login.html] In DispatcherServlet With Name 'HorarioLivre'

- 1 answer

The error describe in the title of this post is being displayed in the eclipse console for my spring mvc application. I try look for other similars examples here in the stackoverflow, but none of this others have solutions for my problem. Follow below some files from my project:

the controller:

package com.HorarioLivre.controller;

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.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.HorarioLivre.core.Sessao;
import com.HorarioLivre.data.UsuarioDAO;

@Controller
public class HorarioLivreController {

    private Sessao sessao;

    @RequestMapping(value="/login", method=RequestMethod.POST)
    public ModelAndView usuario_login(@RequestParam("username") String username, @RequestParam("password") String password) {
        UsuarioDAO usuario = new UsuarioDAO(username, password);

        if(usuario.getUsuario() != null) {
            this.setSessao(new Sessao(usuario.getUsuario()));
        }

        ModelAndView mav = new ModelAndView();
        mav.setViewName("usuario_start");
        mav.addObject("usuario", usuario.getUsuario());

        return mav;
    }

    public Sessao getSessao() {
        return sessao;
    }

    public void setSessao(Sessao sessao) {
        this.sessao = sessao;
    }
}

the 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>HorarioLivre</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>HorarioLivre</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>HorarioLivre</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

the HorarioLivre-servlet.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:p="http://www.springframework.org/schema/p" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="com.horariolivre.controller" />    
    <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/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

Someone can see what's wrong with this code? I tried very hard, but can't figure what's happening.

Ad

Answer

Have you told Spring MVC to scan and which packages to scan for @Controller and @RequestMapping annotations in your Spring config file? It's not in the config that you posted. Something like:

<mvc:annotation-driven />
<context:component-scan base-package="com.HorarioLivre.controller" />
Ad
source: stackoverflow.com
Ad