Java Play 中的配置 - ebean 和 postgresql
Posted
技术标签:
【中文标题】Java Play 中的配置 - ebean 和 postgresql【英文标题】:Configuration in Java Play - ebean and postgresql 【发布时间】:2017-04-09 18:59:32 【问题描述】:我无法让我的 Play Framework 项目正常运行。我想使用 postgresql db 和 ebean,但配置有问题,我不断收到编译错误。你能看看并检查可能是什么原因吗?
我的 build.sbt 文件:
import play.sbt.PlayJava
name := """play-java-intro"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.4-1206-jdbc42",
"javax.persistence" % "persistence-api" % "1.0.2"
)
fork in run := true
plugins.sbt:
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.13")
// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
我的模型课:
package models;
import java.util.*;
import com.avaje.ebean.Finder;
import com.avaje.ebean.Model;
import play.data.format.*;
import play.data.validation.*;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Person extends Model
@Id
private Long id;
@Constraints.Required
public String name;
@Constraints.Required
public String surname;
@Formats.DateTime(pattern="dd/MM/yyyy")
public Date date;
public static Finder<Long,Person> finder = new Finder<Long, Person>(Person.class);
还有错误信息:
[error] com.avaje.ebean.Finder
[error] /home/guras/play-java-intro/app/models/Person.java:6: package com.avaje.ebean does not exist
[error] /home/guras/play-java-intro/app/models/Person.java:7: package com.avaje.ebean does not exist
[error] com.avaje.ebean.Model
[error] /home/guras/play-java-intro/app/models/Person.java:15: cannot find symbol
[error] symbol: class Model
[error] Model
[error] /home/guras/play-java-intro/app/models/Person.java:28: cannot find symbol
[error] symbol: class Finder
[error] location: class models.Person
[error] Finder
[error] /home/guras/play-java-intro/app/models/Person.java:28: cannot find symbol
[error] symbol: class Finder
[error] location: class models.Person
[error] Finder
[info] play.forkrun.protocol.Serializers$playExceptionPickler$$anon$1: Compilation error[package com.avaje.ebean does not exist]
[info] at play.forkrun.protocol.Serializers$playExceptionPickler$.unpickle(Serializers.scala:159)
[info] at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileFailureUnpickler$macro$56$2$.unpickle(Serializers.scala:175)
[info] at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileResultUnpickler$macro$66$2$.unpickle(Serializers.scala:181)
[info] at scala.pickling.Unpickler$class.unpickleEntry(Pickler.scala:79)
[info] at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileResultUnpickler$macro$66$2$.unpickleEntry(Serializers.scala:181)
[info] at scala.pickling.functions$.unpickle(functions.scala:11)
[info] at sbt.serialization.JsonValue$$anonfun$parse$1.apply(SerializedValue.scala:104)
[info] at scala.util.Try$.apply(Try.scala:192)
[info] at sbt.serialization.JsonValue.parse(SerializedValue.scala:104)
[info] at sbt.protocol.BuildValue.value(Values.scala:11)
【问题讨论】:
【参考方案1】:您必须将 ebean jar 作为依赖项添加到您的类路径中。导入失败是因为您的类路径中没有包含这些包的依赖 jar。 您可以在 Maven 中心存储库 here 中找到这些 jars
【讨论】:
现在我在 plugins.sbt 和 "org.avaje" 中有 "addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "2.8.1")" % "ebean" % "2.8.1" 在 build.sbt 中,但 Intellij 无法解决它。你还有别的想法吗?好像根本没有下载那些库。【参考方案2】:关于你的 plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.1.0")
在你的 build.sbt
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
libraryDependencies ++= Seq(
javaJdbc,
javaCore,
"org.postgresql" % "postgresql" % "9.4.1212"
)
您必须启用 ebean 插件才能使用 play 框架。
【讨论】:
以上是关于Java Play 中的配置 - ebean 和 postgresql的主要内容,如果未能解决你的问题,请参考以下文章
Play 2.4 / Ebean / JPA / hibernate-entitymanager 的正确配置是啥?
Lob 使用 play 框架和 Ebean 和 H2 返回 null