经过第一天的部署,小有成就(原谅我吧,就是这么容易满足).接下来就是考虑做个什么应用,大的应用没时间(能力也有限),小的应用也没什么意思,最后决定做一个个人站点(非常没创意...)
简单说下我的想法(只是想法,一切都没实现之前只是愿景)
最重要的模块个人的blog的发布系统(和普通的blog没什么两样):发表blog,留言,查看blog;后续的可能会加上一些小应用,例如:twitter,flickr,rss订阅,利用google的api尽可能多的集成(当然包括Google AdSense),顺便吼下google很好很强大(被拖走...),很期待9月份(听说,听说)将要推出的googl wave,本人申请了wave但是不够幸运。哇,扯了这么多没用的。
正文:在部署成功之后,马上想到的就是测试连接数据库,google采用的是App Engine 数据存储区,为java提供了两种接口jdo和jpa,因为google提供的文档偏重讲解了jdo,所以就选了jdo。
1.创建domain
在grails中安装完app-engine插件之后
grails create-domain-class account创建的领域类中默认创建了两个属性id和property1
import javax.jdo.annotations.*;
// import com.google.appengine.api.datastore.Key;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Account{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id
@Persistent
String property1
static constraints = {
id( visible:false)
}
}
2.创建controller和view
google app-engine可以在本地建立存储区进行测试(一直不明白这个存储区到底是个什么东西),所以不用上传测试,直接在本地测试
grails generate-all account
3.启动app
grails app-engine run
启动之后在创建account的时候总是失败(后台没有报错)
经查原来grails自动创建的AccountController中发现了try了之后没有catch
def save = {
def accountInstance = new Account(params)
if(!accountInstance.hasErrors() ) {
try{
println "before storing id is ${accountInstance.id}"
persistenceManager.makePersistent(accountInstance)
println "after storing id is ${accountInstance.id}"
}catch(e){ //手动加入catch
println "exception!!!!!!!!!: $e"
}
finally{
flash.message = "Account ${accountInstance.id} created"
redirect(action:show,id:accountInstance.id)
}
}
打印出来的异常:
org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException:
The class "The class "Account" is not persistable.
This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found." is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data for the class is not found.
[java] NestedThrowables:
[java] org.datanucleus.exceptions.ClassNotPersistableException:
The class "Account" is not persistable.
This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
凭借我拙略的英文异常提到了3点:
1.account没有被“增强” //这个不可能 @Persistent注释就已经完成增强
2.classpath的问题 //我也将app的jar加入到了classpath 见Grails on google App engine开始
3.没发现注释 // 和第一条差不多
3.解决
貌似结果是没有发现domain account或者增强account出的问题,但是我都是按照手册来的啊,又检查了配置也没有问题,奇怪。
我google搜啊搜啊都没有找到解决办法(要不是用grails创建app的人不多,要不就是这个问题很低级),没办法,只有给一个国外做例子的作者发了邮件(不过我发现他很有可能不是外国人,至少不是美国人,因为他在北京时间18点左右给我回的邮件,哪个鬼会在早上六点一起来就看邮件,至少程序员不会)
他给我回的邮件很简单:
You domain class needs to be in a package when using app-engine. Please post questions to the mailing list or nabble forums
恩,domain应该在package中。(让我发邮件至少得告诉我邮箱,至少论坛中没有,nabble论坛?算了吧,英文不过关,不丢人去了)
随后我将account加入到了一个package中,而且将对应的controller也建立了相应的package,并将accountController放入其中(经测试这是必须的)。
令人惊喜的结果--成功了。
还有两点需要说明:
命令行的方式ctrl+c并不能结束grails的运行,还要在任务管理器中手动结束掉java进程不知道*-nix怎么样,也可能是grails就这么设计的。
在grails app-engin run的最后一步非常的慢,最后找到是因为瑞星的监控,关闭之后就很快了
我的环境是windows powerCmd ue
分享到:
相关推荐
Grails从入门指南(第二版)
一步一步搭建grails应用的源代码,上传的图片全部丢失,只好上传代码。
grails 中文第二版
grails-test-app 目标 使用Groovy来实现RESTful API Web应用程序。 或用于RESTful API实现)或您要使用的任何框架。 使用Robotframework( )编写一个测试用例,以在Google上搜索“ Ruckus Wireless”,并检查是否...
Grails开源项目教学代码第二部分Beginning_Groovy_and_Grails开源项目教学代码第二部分
Grails Grails Grails Grails Grails
Grails入门指南中文第二版
实际上,一个grails插件和一个grails应用基本是完全一样的,同样可以使用grails run-app命令来运行。区别仅在于一个插件的根目录下需要提供一个fooplugin.groovy文件,提供插件的一些描述信息。
Grails权威指南第二版 Grails是一个搭建在动态语言 Groovy 之上的开源 MVC 快速 Web 开发框架。使用 Grails 可以提高 Web 开发的效率,降低 Web 开发的复杂度。 本书由Grails项目负责人Graeme Keith Rocher编写,极...
Grails入门指南第二版学习笔记,有需要的同学可以看一下。
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
grails 开发指南第二版 Who is this book for? This book is for everyone who is looking for a more agile approach to web development with a dynamic scripting language such as Groovy. This includes a ...
How to use Acegi on Grails using Grails Domain class Beans to support Acegi on Grails Grails Acegi Plugin Setting up Acegi Plugin Secure your Ajax Secure your Service
grails-2.1.zip.001
Grails1.1中文文档
grails+Xfire webservice
Grails入门指南中文pdf -- 针对grails1.0.4更新,附加idea8 开发grails的流程
grails1.0开发框架5 类似于ruby on rails的框架。
Grails项目的应用越来越多,而对于初学者来说,在Eclipse下搭建Grails项目是一个难题,这个文档将教会你如何搭建Grails项目,希望对你有所帮助。
"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, Tropicana, and Taco Bell are all using Grails. Are you ready to get started ...