Google app engine - Servlet Mapping for Google App Engine and Spring/404 no mapping found

This post is all about Spring MVC 3 and Google App Engine and their interaction.

The starting point for this project was the Google App Engine’s documentation, the Google Eclipse plugin, and some tutorials found on various sites.

After reading all about the App Engine and Spring, the first thing to do was to create a project in our favorite editor, Eclipse. This generated some necessary files, and gave us a good starting point. As we want to use Spring to perform all its magic, we’ve created a web.xml like this:

01<servlet>

02    <servlet-name>dispatcher</servlet-name>
03    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
04    <load-on-startup>1</load-on-startup>
05</servlet>
06 
07<servlet-mapping>
08    <servlet-name>dispatcher</servlet-name>
09    <url-pattern>/*</url-pattern>
10</servlet-mapping>

This configuration would redirect all incoming requests to our Spring Dispatcher Servlet that will handle everything from there on. At leaset that’s what we’ve thought. After firing up the local App Engine development server, an error appeared for every request issued from the browser (lets say http://localhost:8888/index). We have set up mapping for that particular url in our Spring controller, but we still got the same error:

1Jul 21, 2010 8:02:33 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
2WARNING: No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcher'


After some googling around, we have realized that there is no need for the wildcard in the url-pattern, but if we simply put “/” there, everything will work nicely.

My curiosity didn’t let me rest on this, so I have investigated a bit more. I wanted for every not specified url to fall back on the index page. Lets try adding the wildcard back to the web.xml, and also to include it in the Spring controller:


1@RequestMapping("/*")

2public String home (Model model) {
3    return index(model);
4}


And again an error:

1Jul 21, 2010 8:04:32 AM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod
2WARNING: No matching handler method found for servlet request: path '/WEB-INF/views/index.jsp', method 'GET', parameters map[[empty]]

Okay, expectedly this didn’t go well, so the third combination was the winning one: no wildcard in web.xml, and with wildcard in the Spring controller. And here are the two final codes:

Web.xml

01<servlet>
02    <servlet-name>dispatcher</servlet-name>
03    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
04    <load-on-startup>1</load-on-startup>
05</servlet>
06 
07<servlet-mapping>
08    <servlet-name>dispatcher</servlet-name>
09    <url-pattern>/</url-pattern>
10</servlet-mapping>

Spring controller

1@RequestMapping("/*")
2public String home (Model model) {
3    return index(model);
4}

This have solved the issue that we were having with the App Engine not wanting to forward to the Spring controller.


总结: Google app engine 的bug, 所以在配置app engine + spring MVC 项目时,请求资源找不到 可以尝试通配符配置。


搞了好多天,终于在http://alasdoo.com/2010/07/servlet-mapping-for-google-app-engine-and-spring/ 找到了答案。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值