Abbadon
Abbadon

Reputation: 2703

Spring : Error in mapping request (No mapping found for HTTP request with URI)

Sorry to ask this kind of question once again but I could not solve my problem looking at other threads and Spring doc.

I am using 3.1.0.RELEASE with maven and try to use annotations and java configuration.

Here is 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" 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" version="2.5">

<servlet>
    <servlet-name>WebAppServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/servletConf/web-application-config.xml<!-- ,
            /WEB-INF/servletConf/application-security.xml -->
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>WebAppServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

And here is my file web-application-config.xml.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />

<context:spring-configured />

<context:component-scan base-package="testspring">
    <context:exclude-filter expression=".*_Roo_.*" type="regex" />
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>

<mvc:annotation-driven />

I have two classes. The first one configure a view resolver

package testspring.web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;



@Configuration
public class CostManagerConfig {

 // Resolve logical view names to .jsp resources in the /WEB-INF/jsp directory
    @Bean
    ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;
        }
}

And the second define my controller:

package testspring.web;

import java.util.Comparator;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Handles requests for the application home page.
 */
@Controller

public class HomeController {

/**
     * Default page when no mapping found.
     * @return
     */
    @RequestMapping("/*")
    public String home() {
        System.out.println("HomeController: Passing through...");
        return "home";
    }

}

According to what I configured I guess everything should be directed to my home() function. However it is not the case here are the logs which Apache output:

DEBUG DispatcherServlet - DispatcherServlet with name 'WebAppServlet' processing GET request for [/testSpring/]

DEBUG RequestMappingHandlerMapping - Looking up handler method for path / DEBUG RequestMappingHandlerMapping - Did not find handler method for [/]

WARN PageNotFound - No mapping found for HTTP request with URI [/testSpring/] in DispatcherServlet with name 'WebAppServlet'

DEBUG DispatcherServlet - Successfully completed request

I have tried to change the parameter in the @RequestMapping but it does not change anything ... I have tried the following

@RequestMapping("/*")

@RequestMapping()

@RequestMapping("/")

@RequestMapping("/home")

@RequestMapping("/home.html")

The url I tried to reach are

http://localhost:8080/testSpring/

http://localhost:8080/testSpring/home

http://localhost:8080/testSpring/home.html

Could you please try to help me?

Thank you very much for reading!

Have a nice day;).

Upvotes: 2

Views: 2364

Answers (1)

Oleksandr Bondarenko
Oleksandr Bondarenko

Reputation: 2018

Of course you can't enter HomeController since you excluded it from component scan:

<context:component-scan base-package="testspring">
  <context:exclude-filter expression=".*_Roo_.*" type="regex" />
  <context:exclude-filter expression="org.springframework.stereotype.
  Controller" type="annotation" />
</context:component-scan>

So just comment this row:

<context:exclude-filter expression="org.springframework.stereotype.
Controller" type="annotation" />

Upvotes: 2

Related Questions