Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

No mapping found for HTTP request with URI [/contas/olaMundoSpring] in DispatcherServlet with name 'spring mvc'

Olá! Segui o tutorial mas fica dando: No mapping found for HTTP request with URI [/contas/olaMundoSpring] in DispatcherServlet with name 'spring mvc'. Já vi outro aluno postando a mesma dúvida, mas no caso dele o erro foi a diferença entre OlaMundoSpring da URL e olaMundoSpring do RequestMapping("/olaMundoSpring") Já olhei e esse não é o meu erro. Então aí vai:

----------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>contas</display-name>
        <welcome-file-list>
                <welcome-file>index.html</welcome-file>
                <welcome-file>index.htm</welcome-file>
                <welcome-file>index.jsp</welcome-file>
                <welcome-file>default.html</welcome-file>
                <welcome-file>default.htm</welcome-file>
                <welcome-file>default.jsp</welcome-file>
        </welcome-file-list>

        <!-- Declaracao do servlet do Spring MVC abaixo -->
        <servlet>
                <servlet-name>spring mvc</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <init-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>/WEB-INF/spring-context.xml</param-value>
                </init-param>
        </servlet>

        <servlet-mapping>
                <servlet-name>spring mvc</servlet-name>
                <url-pattern>/</url-pattern>
        </servlet-mapping>
</web-app>

----------- spring-context.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/mvc 
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        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="br.com.caelum.contas" />
        <mvc:annotation-driven />

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

</beans>

----------- OlaMundoController.java ------------
package br.com.caelum.contas.controller;

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

@Controller
public class OlaMundoController {

        @RequestMapping("/olaMundoSpring")
        public String excecute() {
                System.out.println("Executando uma lógica com Spring MVC");
                return "ok";
        }
}

----------- ok.jsp ------------
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Minha primeira lógica com SpringMVC
</body>
</html>
2 respostas

Oi Mauricio,

Você está acessando como a sua aplicação? Está com a URL http://localhost:8080/contas/olaMundoSpring?

Como está o log do seu servidor na hora de subi-lo?

Abraço!

solução!

Oi Joviane! Achei a solução neste exato momento. O Tomcat 9 não estava fazendo o build dentro da pasta WebApp do tomcat. Ao fazer essa alteração ele passou a empacotar corretamente com as classes dentro.