sebarmeli
sebarmeli

Reputation: 18265

No mapping found using Spring3 MVC + Maven2 on GAE

I'm getting a weird issue trying to integrate Spring MVC and Maven in a Google AppEngine webapp.

This is my web.xml

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

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

this is my SpringMVC config file

<context:annotation-config />

<context:component-scan base-package="com.mypackage" />

<mvc:annotation-driven/>

<bean id="viewResolver"  
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"  
            p:prefix="/WEB-INF/jsp/view/"   
                p:suffix=".jsp"
                    p:viewClass="org.springframework.web.servlet.view.JstlView"   />  

this is my controller:

@Controller
@RequestMapping(value = "/hello")
public class HelloController {
     @RequestMapping(method = RequestMethod.GET)  
     public String helloGet(ModelMap map) {  
            map.put("name", "seb!");  
            return "hello";  
     }  
}

and this is my view located at webapp/WEB-INF/jsp/view/hello.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!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>Hello Controller</title>
    </head>
    <body>
        <h1>Hello ${name}!</h1>
    </body>
</html>

and this is my pom contains dependencies to SpringMVC 3.0.3, servlet-api 2.5, jstl 1.2

I'm keeping getting

WARNING: No mapping found for HTTP request with URI [/WEB-INF/jsp/view/hello.jsp] in DispatcherServlet with name 'dispatcher'

when I hit localhost:8080/hello and I can't figure out why. Is it due to GAE or am I missing anything in some config?

Update: If I dispatch the URL coming from /app/* to Spring Dispatcher, changing my web.xml like this:

<servlet-mapping>  
      <servlet-name>dispatcher</servlet-name>  
      <url-pattern>/app/*</url-pattern>  
   </servlet-mapping>`

it'll work, but I just want to use landing pages and use the root of the app

Upvotes: 2

Views: 1103

Answers (1)

hleinone
hleinone

Reputation: 4480

I've faced this issue in the past. If I recall correctly it worked properly when deployed, but failed on the development server. My solution was to map the dispatcher servlet to /app/* instead of /*.

That results /app in all the URL paths in your application. If you want to get rid of this, use URL rewriting.

In web.xml:

<filter>
    <filter-name>urlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>urlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite default-match-type="wildcard">
    <rule>
        <from>/</from>
        <to>/app/</to>
    </rule>
    <rule>
        <from>/_ah/**</from>
        <to>/_ah/$1</to>
    </rule>
    <rule>
        <from>/**</from>
        <to>/app/$1</to>
    </rule>
    <outbound-rule>
        <from>/_ah/**</from>
        <to>/_ah/$1</to>
    </outbound-rule>
    <outbound-rule>
        <from>/app/**</from>
        <to>/$1</to>
    </outbound-rule>
</urlrewrite>

Upvotes: 3

Related Questions