摘要:
本教程,主要展示GAE如何集成Spring 3.0 MVC REST框架,同时,实现一个小案例。
所使用技术和工具:
- 1. Eclipse-Jee-Juno (version 4.2)
- 2. JDK 1.6
- 3. Google Plugin for Eclipse
- 4. Google App Engine Java SDK 1.7.4
- 5. Spring 3.1.0
-
项目集成Spring 3.0 MVC REST 需要依赖以下jar
- 1. aopalliance-1.0.jar
-
2. commons-logging-1.1.1.jar
-
3. spring-aop-3.1.0.RELEASE.jar
-
4. spring-asm-3.1.0.RELEASE.jar
-
5. spring-beans-3.1.0.RELEASE.jar
-
6.spring-context-3.1.0.RELEASE.jar
-
7. spring-context-support-3.1.0.RELEASE.jar
-
8. spring-core-3.1.0.RELEASE.jar
-
9. spring-expression-3.1.0.RELEASE.jar
-
10. spring-web-3.1.0.RELEASE.jar
-
11. spring-webmvc-3.1.0.RELEASE.jar
-
>>准备好Jar包以后,将这些jar包拷贝到项目的war/WEB-INF/lib 中
- >>导入后,通过Configure Build Path…配置引用下这些包就好了
-
>>配置SpringMVC,首先我们需要在war/WEB-INF/ 下创建一个Spring XML bean的配置文件 {YourServletName}-servlet.xml,用来定义bean 和 试图解析器
- <beans xmlns="http://www.springframework.org/schema/beans"
-
xmlns:context="http://www.springframework.org/schema/context"
-
xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/mvc
-
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
-
-
-
<context:component-scan base-package="com.javawill" />
-
-
-
<bean
-
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
-
<property name="prefix">
-
<value>/WEB-INF/jsp/</value>
-
</property>
-
<property name="suffix">
-
<value>.jsp</value>
-
</property>
-
</bean>
-
-
</beans>
-
>>同时,我们需要将Spring 集成到我们的web.xml中,有的人可能IDE无法显示web.xml的内容,只需要刷新web.xml 文件(注意是文件,不是内容)
- <?xml version="1.0" encoding="utf-8" standalone="no"?>
-
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-
-
<servlet>
-
<servlet-name>baifeibai</servlet-name>
-
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
-
<load-on-startup>1</load-on-startup>
-
</servlet>
-
<servlet-mapping>
-
<servlet-name>baifeibai</servlet-name>
-
<url-pattern>*.do</url-pattern>
-
</servlet-mapping>
-
<context-param>
-
<param-name>contextConfigLocation</param-name>
-
<param-value>/WEB-INF/baifeibai-servlet.xml</param-value>
-
</context-param>
-
-
<listener>
-
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-
</listener>
-
<welcome-file-list>
-
<welcome-file>index.html</welcome-file>
-
</welcome-file-list>
-
<servlet>
-
<servlet-name>SystemServiceServlet</servlet-name>
-
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
-
<init-param>
-
<param-name>services</param-name>
-
<param-value />
-
</init-param>
-
</servlet>
-
<servlet-mapping>
-
<servlet-name>SystemServiceServlet</servlet-name>
-
<url-pattern>/_ah/spi/*</url-pattern>
-
</servlet-mapping>
-
</web-app>
-
>>现在我们看看我们项目的新结构,并实现一个简单的业务,通过Controller 定义一个变量值,并在JSP上展现出来
-
>>定义Controller.java
-
-
-
-
package com.javawill.example.spring.controller;
-
-
import org.springframework.stereotype.Controller;
-
import org.springframework.ui.Model;
-
import org.springframework.web.bind.annotation.RequestMapping;
-
-
-
-
-
-
-
@Controller
-
public class SpringController {
-
@RequestMapping("/example/welcome.do")
-
public String Welcome(Model model, String inputval){
-
if ( inputval == null || ("".equals(inputval))) {
-
inputval = "您可以试试在下面的输入框输入值,测试下Spring的传参!";
-
} else {
-
inputval = "您之前输入的值为:" + inputval;
- }
-
model.addAttribute("hello", "您好,欢迎您来到GAE+SpringMVC学习项目演示网站!");
-
model.addAttribute("msg", inputval);
-
return "example/spring/welcome";
- }
- }
=================================================================== 本教程系列为本人写技术博客练笔之作,高手请无视,转载请点明出处!
===================================================================
分享到:
相关推荐
GAE-SpringMVC_Example SpringMVC 应用示例,支持:Google AppEngine v1.9.15 和 SpringMVC v3.1.1 是一个建立在[集成开发环境] Moon Eclipse Service Release 1 (4.4.1) 上的项目,因此您可以将其导入Eclipse 并...
实现了spring3+springmvc+jpa2.0+gae之间的集成,项目可直接运行
GAE 集成程序,共有三个软件包,解压后安装包里的python然后运行SDU里的exe文件,最后运行客户端加服务端中localproxy中的proxy.py就可以了
GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则
Eclipse开发 Gae,Struts2,Spring,云计算,学习gae云计算的好例子
图自编码器GAE的pytorch实现,参考论文vgae
pass之GAE入门教程, 学习GAE
实现了gae与spring3之间的集成
图形自动编码器GAE的pytorch实现,可参考论文VGAE
GAE平台开发应用时,简单的webapp框架的使用
《GAE编程指南》是一种云计算服务,跟其他的同类产品不同,它提供了一种简单的应用程序构建模型,通过这种模型,你可以轻松地构建出能够容纳数百万用户的应用程序。《GAE编程指南》是介绍使用这个强大平台的专家级...
云计算下的PaaS中的GAE和SAE平台
GAE上可以用的JAVA Blog源代码 可以在GAE上直接使用,支持图片上传等。 源代码是修改其他网友的普通blog程序而来,只做了必要的修改,原结构保留 最新版本请去主页下载 http://redpower1998.appspot.com 主页包括...
《GAE编程指南》是一种云计算服务,跟其他的同类产品不同,它提供了一种简单的应用程序构建模型,通过这种模型,你可以轻松地构建出能够容纳数百万用户的应用程序。《GAE编程指南》是介绍使用这个强大平台的专家级...
实现了spring+gae+hibernate的集成
百度的bae跟谷歌的gae对比,百度的资源限制很少,但是资源很少,教程很少。。
关于GAE的教程、工具与文档(建站) 全
GAE(Google App Engine)空间 GAE(Google App Engine)空间申请使用教程及 GAE域名捆绑方法使用教程及 GAE域 GAE(Google App Engine)空间申请使用教程及 GAE域名捆绑方法捆绑方法
gae-java-mini-profiler.zip,google a p p engine java runtime的mini profiler(灵感来自于https://github.com/kamens/gae_mini_profiler上的python gae_mini_profiler和...
GAE虽然支持java了,但不幸的是依然不支持php 但是我们可以使用基于java的Quercus基本上可以100%的支持PHP语言