1

I'm trying to build a spring dynamic web project using Gradle on eclipse. My problem is that my spring dispatcher don't see the controller and i don't know why.

My project is like this : http://hpics.li/8c7aca3

As you can see, my controller don't have the "s" specifying that spring detected it.

Here my "web.xml" file :

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <servlet>
        <servlet-name>springmvcdispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>springmvcdispatcher</servlet-name>
        <url-pattern>/</url-pattern>

    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/springmvcdispatcher-servlet.xml
        </param-value>

    </context-param>

</web-app>

here my spring dispatcher :

<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

    <context:component-scan base-package="com.nostatikmedia.livelizard.controller"></context:component-scan>
    <context:annotation-config/>
    <bean
        class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <mvc:annotation-driven/>

</beans>

and finaly my controller :

package com.nostatikmedia.livelizard.controller;

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

@Controller
@RequestMapping("/")
public class MainController {

    @RequestMapping(method=RequestMethod.GET)
    public String indexMethod(Model model){
        System.out.println("**********************************************************");
        return "authentication";
    }

}

When i run the project in tomcat8.0 server, i have this message :

No mapping found for HTTP request with URI [/testproject/] in DispatcherServlet with name 'springmvcdispatcher'.

Anyone can help me ?

Tanks.

Toumi Ilyes
  • 45
  • 3
  • 10
  • Are you sure that you start your app with such name? Check the tomcat admin whether you have your app actually deployed. One more thing: place your context config BEFORE the servlet mapping. – user May 08 '15 at 09:08
  • I cheked my server and the project is deployed. And put contedt config before the servlet mapping dosen't change anything – Toumi Ilyes May 08 '15 at 09:21
  • I don't think, that it could be the issue, but try to add RequestMapping value to the controller method as well. Still checking the overall situation... – user May 08 '15 at 09:24
  • shouldn't the `url-pattern` for `springmvcdispatcher` be `/*` ? Check the context path for your project. I guess your project name is `testproject`. – Kishore May 08 '15 at 09:31
  • Add this in web.xml in `` tag - `1` – vivekpansara May 08 '15 at 09:43
  • Try calling your controllers with a different extension (.do for example) and update the servlet-mapping to suit-- dispatcher *.do – Varun May 08 '15 at 10:44

0 Answers0