blue-sky
blue-sky

Reputation: 53826

Not finding request mapping within spring controller

I'm just trying to create a simple spring web app. When I try to navigate to http://localhost:8080/spring-test/VIEW/VIEW I receive 404 error :

HTTP Status 404 - /spring-test/VIEW/VIEW

type Status report

message /spring-test/VIEW/VIEW

description The requested resource (/spring-test/VIEW/VIEW) is not available.

Is my below config correct ?

TestController.java :

package com;

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


@Controller
@RequestMapping("VIEW")
public class TestController {

    @RequestMapping("VIEW")
    public String showView(final ModelMap argMap) {
        return "test.jsp";
    }

}

applicationContext.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"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


 <bean id="myController" class="com.TestController">

</bean>

 <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
        <property name="order" value="0" />
        <property name="portletModeMap">
            <map>
                <entry key="view" value-ref="myController" />
            </map>
        </property>
    </bean>


</beans>

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>Spring3MVC</display-name>


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/*.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

Project layout :

enter image description here

Upvotes: 0

Views: 3012

Answers (3)

blue-sky
blue-sky

Reputation: 53826

I needed to change servlet mapping to :

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

Kudos to spring MVC servlet mapping

Upvotes: 1

Elbek
Elbek

Reputation: 3484

<mvc:annotation-driven /> is missing 

Have a look from here

Upvotes: 1

J&#39;eBofu
J&#39;eBofu

Reputation: 11

I may be wrong but your serlvet mapping seems to redirect to your spring servlet if the URL ends with html. See if accessing /spring-test/VIEW/VIEW.html gets you the same error.

Upvotes: 1

Related Questions