app mvc框架

前段时间,我写了一篇关于如何使用Spring MVC实现Restful Web API的文章 。 阅读我以前的文章以了解它。

在那篇文章中,它开发了一个简单的Rest示例。 为了测试该应用程序,将文件复制到Web服务器(例如Tomcat )中,然后返回访问字符1的http:// localhost:8080 / RestServer / characters / 1信息。

在当前文章中,我将解释如何将应用程序转换为Google App Engine并使用Maven部署到Google的基础架构中。 当然,在这种情况下,我们将部署Rest Spring MVC应用程序,但是可以使用相同的方法将Spring MVC Web应用程序(或使用其他Web框架开发的任何其他应用程序)迁移到GAE。

首先,显然,您应该创建一个Google帐户并注册一个新的应用程序 (请记住名称,因为它将在下一步中使用)。 之后,您可以开始迁移。

需要进行三个更改,创建定义应用程序名称的appengine-web.xml ; 使用Google帐户信息将服务器标签添加到settings.xml,并修改pom.xml以添加GAE插件及其依赖项。

让我们从appengine-web.xml开始。 GAE使用此文件来配置应用程序,并将其创建到WEB-INF目录(与web.xml处于同一级别)。

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://appengine.google.com/ns/1.0 http://googleappengine.googlecode.com/svn/branches/1.2.1/java/docs/appengine-web.xsd"><application>alexsotoblog</application><version>1</version><system-properties><property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/></system-properties><precompilation-enabled>false</precompilation-enabled><sessions-enabled>true</sessions-enabled>
</appengine-web-app>

最重要的字段是应用程序标签。 此标记包含我们应用程序的名称(在您注册新的Google应用程序时定义)。

其他标记包括版本,系统属性和环境变量以及其他配置,例如您是否希望预编译以提高性能或应用程序需要会话。

而且您的项目不再需要修改,现在仅Maven文件将被触摸。

settings.xml中 ,应该添加帐户信息:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"><localRepository>/media/share/maven_repo</localRepository><servers><server><id>appengine.google.com</id><username>my_account@gmail.com</username><password>my_password</password></server></servers></settings>

看到这和在Maven中注册任何其他服务器一样容易。

最后是最繁琐的部分,修改pom.xml

首先要添加新属性:

<gae.home>/media/share/maven_repo/com/google/appengine/appengine-java-sdk/1.5.5/appengine-java-sdk-1.5.5</gae.home>
<gaeApplicationName>alexsotoblog</gaeApplicationName>
<gaePluginVersion>0.9.0</gaePluginVersion>
<gae.version>1.5.5</gae.version><!-- Upload to http://test.latest.<applicationName>.appspot.com by default -->
<gae.application.version>test</gae.application.version>

在第一行,我们定义Appengine Java SDK的位置。 如果已经安装,则在此标记中插入位置,如果没有,请复制此pom的相同位置,然后将maven存储库目录(在我的情况下为/ media / share / maven_repo)更改为您的目录。 通常,您的Maven存储库位置将是/home/user/.m2/repositoriesMaven将在部署时为您下载SDK

下一步是添加Maven GAE存储库。

<repositories><repository><id>maven-gae-plugin-repo</id><url>http://maven-gae-plugin.googlecode.com/svn/repository</url><name>maven-gae-plugin repository</name></repository>
</repositories><pluginRepositories><pluginRepository><id>maven-gae-plugin-repo</id><name>Maven Google App Engine Repository</name><url>http://maven-gae-plugin.googlecode.com/svn/repository/</url></pluginRepository>
</pluginRepositories>

因为我们的项目是虚拟项目, 所以不使用Datanucleus 。 对于更复杂的项目,需要使用例如JDO来访问数据库,应添加下一个依赖项:

<dependency><groupId>javax.jdo</groupId><artifactId>jdo2-api</artifactId><version>2.3-eb</version><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.google.appengine.orm</groupId><artifactId>datanucleus-appengine</artifactId><version>1.0.6.final</version>
</dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-core</artifactId><version>1.1.5</version><scope>runtime</scope><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>geronimo-jta_1.1_spec</artifactId><version>1.1.1</version><scope>runtime</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>geronimo-jpa_3.0_spec</artifactId><version>1.1.1</version><scope>runtime</scope>
</dependency>

如果您使用的是Datanucleus ,则应注册maven-datanucleus-plugin 。 请注意根据您的项目正确配置它。

<plugin><groupId>org.datanucleus</groupId><artifactId>maven-datanucleus-plugin</artifactId><version>1.1.4</version><configuration><!--Make sure this path contains your persistentclasses!--><mappingIncludes>**/model/*.class</mappingIncludes><verbose>true</verbose><enhancerName>ASM</enhancerName><api>JDO</api></configuration><executions><execution><phase>compile</phase><goals><goal>enhance</goal></goals></execution></executions><dependencies><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-core</artifactId><version>1.1.5</version><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-rdbms</artifactId><version>1.1.5</version></dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-enhancer</artifactId><version>1.1.5</version></dependency></dependencies>
</plugin>

现在,添加了Google App Engine依赖项。

<dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-1.0-sdk</artifactId><version>${gae.version}</version>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-tools-api</artifactId><version>1.3.7</version>
</dependency>

然后,如果您想测试GAE 功能 (在我们的虚拟项目中未使用),则添加下一个GAE库:

<dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-labs</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-stubs</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-testing</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency>

接下来的更改是对maven-war-plugin的修改,其中将appengine-web.xml包含到生成的包中:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><webResources><resource><directory>src/main/webapp</directory><filtering>true</filtering><includes><include>**/appengine-web.xml</include></includes></resource></webResources></configuration>
</plugin>

最后添加maven-gae-plugin并将其配置为将应用程序上传到appspot

<plugin><groupId>net.kindleit</groupId><artifactId>maven-gae-plugin</artifactId><version>${gaePluginVersion}</version><configuration><serverId>appengine.google.com</serverId></configuration><dependencies><dependency><groupId>net.kindleit</groupId><artifactId>gae-runtime</artifactId><version>${gae.version}</version><type>pom</type></dependency></dependencies>
</plugin>

看到<serviceId>标记包含先前在settings.xml文件中定义的服务器名称。

另外,如果您使用的是maven-release-plugin ,则可以在release:perform目标期间将应用程序自动上传到appspot

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>2.2.1</version><configuration><goals>gae:deploy</goals></configuration>
</plugin>

现在运行gae:deploy目标。 如果您已经安装了Appengine Java SDK ,那么您的应用程序将被上传到您的GAE网站。 但是,如果这是您第一次运行该插件,则会收到错误消息。 不要惊慌,发生此错误是因为Maven插件未在您在<gae.home>标记中指定的目录中找到Appengine SDK 。 但是,如果您已将gae.home位置配置到本地Maven存储库中,只需运行gae:unpack目标,即可正确安装SDK ,因此当您重新运行gae:deploy时,您的应用程序将上传到Google基础架构中。

在后例子中,你可以去http://alexsotoblog.appspot.com/characters/1http://alexsotoblog.appspot.com/characters/1和JSON格式字符信息显示到浏览器中。

正如我在文章开头所指出的,相同的过程可以用于任何Web应用程序,而不仅仅是Spring Rest MVC

由于教学目的,对应用程序pom进行了所有修改。 我的建议是,您要使用GAE相关标签创建父pom ,因此必须上传到Google App Engine的每个项目都来自同一pom文件。

我希望您发现这篇文章有用。

本周,我在devoxx ,在那与我见面;)我将在17日(星期四)13:00发表有关通过聚合和最小化加速Javascript和CSS下载时间的演讲 。

完整的pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>rest</artifactId><name>Rest</name><packaging>war</packaging><version>1.0.0-BUILD-SNAPSHOT</version><properties><java-version>1.6</java-version><org.springframework-version>3.0.4.RELEASE</org.springframework-version><org.aspectj-version>1.6.9</org.aspectj-version><org.slf4j-version>1.5.10</org.slf4j-version><!-- Specify AppEngine version for your project. It should match SDK version pointed to by ${gae.home} property (Typically, one used by your Eclipse plug-in) --><gae.home>/home/alex/.m2/repository/com/google/appengine/appengine-java-sdk/1.5.5/appengine-java-sdk-1.5.5</gae.home><gaeApplicationName>alexsotoblog</gaeApplicationName><gaePluginVersion>0.9.0</gaePluginVersion><gae.version>1.5.5</gae.version><!-- Upload to http://test.latest.<applicationName>.appspot.com by default --><gae.application.version>test</gae.application.version></properties><dependencies><!-- Rest --><dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId><version>2.2.4-1</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-core-lgpl</artifactId><version>1.8.5</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-lgpl</artifactId><version>1.8.5</version></dependency><!-- GAE libraries for local testing as described here: http://code.google.com/appengine/docs/java/howto/unittesting.html --><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-labs</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-stubs</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-testing</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-1.0-sdk</artifactId><version>${gae.version}</version></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-tools-api</artifactId><version>1.3.7</version></dependency><!-- Spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${org.springframework-version}</version><exclusions><!-- Exclude Commons Logging in favor of SLF4j --><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${org.springframework-version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-oxm</artifactId><version>${org.springframework-version}</version></dependency><!-- AspectJ --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>${org.aspectj-version}</version></dependency><!-- Logging --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${org.slf4j-version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>jcl-over-slf4j</artifactId><version>${org.slf4j-version}</version><scope>runtime</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${org.slf4j-version}</version><scope>runtime</scope></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.15</version><exclusions><exclusion><groupId>javax.mail</groupId><artifactId>mail</artifactId></exclusion><exclusion><groupId>javax.jms</groupId><artifactId>jms</artifactId></exclusion><exclusion><groupId>com.sun.jdmk</groupId><artifactId>jmxtools</artifactId></exclusion><exclusion><groupId>com.sun.jmx</groupId><artifactId>jmxri</artifactId></exclusion></exclusions><scope>runtime</scope></dependency><!-- @Inject --><dependency><groupId>javax.inject</groupId><artifactId>javax.inject</artifactId><version>1</version></dependency><!-- Servlet --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.1</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!-- Test --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.7</version><scope>test</scope></dependency></dependencies><repositories><!-- For testing against latest Spring snapshots --><repository><id>org.springframework.maven.snapshot</id><name>Spring Maven Snapshot Repository</name><url>http://maven.springframework.org/snapshot</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository><!-- For developing against latest Spring milestones --><repository><id>org.springframework.maven.milestone</id><name>Spring Maven Milestone Repository</name><url>http://maven.springframework.org/milestone</url><snapshots><enabled>false</enabled></snapshots></repository><!-- GAE repositories --><repository><id>maven-gae-plugin-repo</id><url>http://maven-gae-plugin.googlecode.com/svn/repository</url><name>maven-gae-plugin repository</name></repository></repositories><pluginRepositories><pluginRepository><id>maven-gae-plugin-repo</id><name>Maven Google App Engine Repository</name><url>http://maven-gae-plugin.googlecode.com/svn/repository/</url></pluginRepository></pluginRepositories><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${java-version}</source><target>${java-version}</target></configuration></plugin><!-- Adding appengine-web into war --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><webResources><resource><directory>src/main/webapp</directory><filtering>true</filtering><includes><include>**/appengine-web.xml</include></includes></resource></webResources><warName>abc</warName></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>install</id><phase>install</phase><goals><goal>sources</goal></goals></execution></executions></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>aspectj-maven-plugin</artifactId><!-- Have to use version 1.2 since version 1.3 does not appear to work with ITDs --><version>1.2</version><dependencies><!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>${org.aspectj-version}</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjtools</artifactId><version>${org.aspectj-version}</version></dependency></dependencies><executions><execution><goals><goal>compile</goal><goal>test-compile</goal></goals></execution></executions><configuration><outxml>true</outxml><source>${java-version}</source><target>${java-version}</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><junitArtifactName>junit:junit</junitArtifactName></configuration></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><version>1.0-beta-1</version></plugin><!-- The actual maven-gae-plugin. Type "mvn gae:run" to run project, "mvn gae:deploy" to upload to GAE. --><plugin><groupId>net.kindleit</groupId><artifactId>maven-gae-plugin</artifactId><version>${gaePluginVersion}</version><configuration><serverId>appengine.google.com</serverId></configuration><dependencies><dependency><groupId>net.kindleit</groupId><artifactId>gae-runtime</artifactId><version>${gae.version}</version><type>pom</type></dependency></dependencies></plugin></plugins></build>
</project>

下载代码。
音乐: http : //www.youtube.com/watch?v = Nba3Tr_GLZU

参考:来自JCG合作伙伴 Alex Soto 在Google App Engine上的Spring MVC和REST,来自One Jar To Rule All All博客。

相关文章 :

  • 使用Spring MVC开发Restful Web服务
  • Spring MVC开发–快速教程
  • jqGrid,REST,AJAX和Spring MVC集成
  • 使用Spring 3.1和基于Java的配置构建RESTful Web服务,第2部分
  • Spring MVC3 Hibernate CRUD示例应用程序
  • Google AppEngine(GAE)中的多租户

翻译自: https://www.javacodegeeks.com/2011/12/spring-mvc-and-rest-at-google-app.html

app mvc框架

app mvc框架_Google App Engine上的Spring MVC和REST相关推荐

  1. Google App Engine上的Spring MVC和REST

    前段时间,我写了一篇关于如何使用Spring MVC实现Restful Web API的文章 . 阅读我以前的文章以了解它. 在那篇文章中,开发了一个简单的Rest示例. 为了测试该应用程序,将文件复 ...

  2. 从零开始学java 框架_从零开始学 Java - 搭建 Spring MVC 框架

    如果创建一个 Spring 项目 Spring MVC 框架在 Java 的 Web 项目中应该是无人不知的吧,你不会搭建一个 Spring 框架?作为身为一个刚刚学习Java的我都会,如果你不会的话 ...

  3. Java框架搭建-Maven、Mybatis、Spring MVC整合搭建

    Java框架搭建-Maven.Mybatis.Spring MVC整合搭建 1. 下载eclipse 到网站下载 http://www.eclipse.org/downloads/packages/e ...

  4. [Spring mvc 深度解析(三)] 创建Spring MVC之器

    第9章 创建Spring MVC之器 ​ 本章将分析Spring MVC自身的创建过程.首先分析Spring MVC的整体结构,然后具体分析每一层的创建过程. 1 整体结构介绍 Spring MVC中 ...

  5. APP自动化测试框架----启动APP(java)

    欢迎大家关注我的个人公众号:小朱谈软件测试,全是干货哦. 接下来就是需要启动APP,如何启动app呢?首先要获取包名,然后获取launcherActivity.获取这两个关键东西的方法很多,这里就不一 ...

  6. java框架高频面试题2(Spring MVC面试题)

    目录 一.spring MVC介绍 二.什么是spring MVC? 三.介绍下Spring MVC的执行流程 总结:SpringMVC框架的总结(常用注解和三大重点) 常用注解 (1)RestCon ...

  7. spring mvc学习(4):第一个spring mvc项目

    一个Spring MVC的项目如何创建?请看这里. 代码编辑器:Intellij IDEA 请提前在电脑上配置好自己的tomcat! 该文属于小白教程,适合初学者. 1 创建Spring MVC项目 ...

  8. 关于jQuery在Asp.Net Mvc 框架下Ajax文件上传的实现

    1. 实现传统的网络文件上传解决方案 首先,我先实现一个传统的网络文件上传方案,建立一个web页面,我还需要一个<form>和两个<input>元素就能解决问题,如在Index ...

  9. mvc框架java包怎么划分_java – 在MVC模式中将模型和动作划分为类...

    原则上,例如domain model,模型层,例如"模型",应分为以下几个部分: > Entities,例如域对象(如您的员工)和value objects.每个实体不仅包含 ...

最新文章

  1. IT行业HR:我们很缺人...
  2. WebLogic 数据源密码加密
  3. JavaScript学习一
  4. BeetleX网关自定义请求日志插件
  5. ubuntu php7.4,在Ubuntu 18.04/19.04/16.04版本上安装PHP 7.4的简单方法
  6. sh 脚本 访问 路径 权限不够_IC设计之脚本语言介绍
  7. EMC -- DFS篇(Documentum Foundation Services)
  8. Linux文件内容查阅
  9. golang 中strconv包用法
  10. 数学——对数公式log常识回顾
  11. vue 自定义marquee横向无缝滚动组件
  12. 郁闷,俺被S3C2416 狠狠的暗算了一把。
  13. 如何搜索网易云中的评论
  14. 使用网络调试助手通过MQTT协议接入到华为云物联网平台
  15. 羊毛出在狗身上,猪来买单
  16. 用Python自动生成数据日报!
  17. rtl8723bu linux wifi驱动移植教程
  18. oracle中的replace into
  19. 西安拟制定羊肉泡馍肉夹馍制作标准
  20. 专访:黑客段子手“呆子不开口”| 宅客故事

热门文章

  1. 投资理财要趁早,基金风险是最小!
  2. Ajax基本案例详解之$.get的实现
  3. Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
  4. 如何用xshell上宝塔
  5. 狂神说spring笔记
  6. SpringBoot 使用Thymeleaf模板 没有提示
  7. No primary or default constructor found for interface java.util.List
  8. 阿里云服务器本地连接(windows) 阿里云服务器和本地的磁盘共享数据
  9. mysql unique count_MySQL - Count Number of Unique Values
  10. RabbitMQ--topic