您的位置:首页 > 移动开发

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

2013-09-25 10:34 281 查看
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:

1
Jul 21, 2010 8:02:33 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
2
WARNING: 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
(
"/*"
)
2
public
String home (Model model) {
3
return

index(model);
4
}
And again an error:

1
Jul 21, 2010 8:04:32 AM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod
2
WARNING: 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
(
"/*"
)
2
public
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/ 找到了答案。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐