`
somefuture
  • 浏览: 1078991 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Play!2.1 EBean配置

阅读更多

本文是在Play 2.1下进行的测试,不过很可能也适合于Play2.0.

 

有兴趣自己研究的可以参考:

【【【【【【【【

http://www.playframework.com/documentation/2.1.x/JavaEbean

http://stackoverflow.com/questions/14963056/play-framework-database-search

http://stackoverflow.com/questions/16361896/play-framework-2-1-ebean-construction

】】】】】】】】

打开Ebean的方法是在conf/application.conf里打开ebean.default="models.*"

先说下什么是Ebean吧。Ebean是一个开源的Java ORM管理工具,

详细信息可以从官网http://www.avaje.org/了解,只要知道它是方便实体操作的框架是可以了。

要注意的一点是:Ebean好像和JPA不能同时用。我用了出错严重,希望指点。

 

ebean.default="models.*"是conf文件中默认的写法,

它的意思是说这个ebean要管理的类(实体)在models包下面。

所以如果你的包不是这种结构要自己改过来,多个类(包)用逗号分开就行。

play提供了一种用独立文件进行配置的方法,

新建一个conf/ebean.properties文件,把配置信息写里面也行。有兴趣的可以试试。

 

然后在实体类里增加一个Finder。可以很方便的进行数据库操作。可以参考

http://www.playframework.com/documentation/2.0.1/api/java/play/db/ebean/Model.Finder.html#Model.Finder(java.lang.String, java.lang.Class, java.lang.Class)

定义方式大致是:

public static Finder<A, B> finder = new Finder<A, B>(A.class, B.class);

 其中A是主键的类型,B是实体的类型。

需要导入的是

import play.db.ebean.Model.Finder;

 依赖包是\repository\local\play\play-java-ebean_2.10\2.1.0\jars\play-java-ebean_2.10.jar.

这样编译会报错,还需要依赖\repository\local\org.avaje.ebeanorm\avaje-ebeanorm-api\3.1.1\jars\avaje-ebeanorm-api.jar。

现在编译可以通过,但有运行时异常

ClassNotFoundException: com.avaje.ebeaninternal.server.core.DefaultServerFactory

 加入包\org.avaje.ebeanorm\avaje-ebeanorm-server\3.1.2\jars\avaje-ebeanorm-server.jar后又报

ClassNotFoundException: com.avaje.ebean.enhance.agent.EnhanceConstants

 继续加入包\org.avaje.ebeanorm\avaje-ebeanorm-agent\3.1.1\jars\avaje-ebeanorm-agent.jar

终于可以了。

 

 

 

 

 

 

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics