0

I experiencing this problem when try to access local host uri http://localhost:8080/spring/olaMundoSpring it is returning in browser:

STATUS 404 The requested resource is not available.

And:

No mapping found for HTTP request with URI [/spring/olaMundoSpring] in >DispatcherServlet with name 'Spring MVC Dispatcher Servlet'.

spring-context.xml seems to be okay:

set 05, 2016 9:45:24 PM >org.springframework.beans.factory.xml.XmlBeanDefinitionReader >loadBeanDefinitions INFORMAÇÕES: Loading XML bean definitions from ServletContext resource [/WEB->INF/spring-context.xml]

Controller:

package br.com.jayybe.spring; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Controle { @RequestMapping("/olaMundoSpring") public String execute() { System.out.println("Executando a lógica com Spring MVC"); return "ok"; } } 

IDE Eclipse DIR

web.xml:

<web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>Spring MVC Dispatcher Servlet</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> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</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.jayybe.spring" /> <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> 

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jayybe</groupId> <artifactId>spring</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>spring Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.2.4.RELEASE</version> </dependency> <!-- Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> </dependencies> <build> <finalName>spring</finalName> </build> </project> 
2
  • 1
    I can't see anything wrong with your test. What I would try is set a breakpoint in DispatcherServlet.doDispatch and start from there. Commented Sep 6, 2016 at 23:25
  • What should I expect to test/debug there? Commented Sep 10, 2016 at 19:14

1 Answer 1

1

Try changing your annotation like this:

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

Change your component scan:

<context:component-scan base-package="br.*" /> 

And don't use a name with white spaces for the servlet-mapping

Sign up to request clarification or add additional context in comments.

1 Comment

I did what you said, it didn't worked, but I don't know I, I reinstalled eclipse, re-imported project and it worked.... why we shoudn't use white spaces in servlet-mapping?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.