我正在尝试将一个简单的应用程序连接到两个数据库,该应用程序有一个子项目。 默认数据库的模型在主项目中,而第二个数据库的模型在子项目中,如此;
root/app/models/MainModel
root/sub/app/mods/SubModel
现在我像这样配置application.conf;
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
#db.default.user=sa
#db.default.password=""
db.sub.driver=org.postgresql.Driver
db.sub.url="jdbc:postgresql://localhost:5432/test"
db.sub.username= postgres
db.sub.password="password@1"
ebean.default = ["models.*"]
ebean.sub = ["mods.*"]
(是的,我使用postgre作为第二个数据库) 和build.sbt一样
lazy val sub = project.in(file("sub")).enablePlugins(PlayEbean, PlayEnhancer)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
.aggregate(sub)
.dependsOn(sub)
playEbeanModels in Compile := Seq("models.*", "mods.*")
根/应用/模型/ MainModel:
package models;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class MainModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
public Integer id;
public String name;
}
和root / sub / app / mods / SubModel:
package mods;
import javax.persistence.Entity;
import javax.persistence.Id;
import com.avaje.ebean.Model;
@Entity
public class SubModel extends Model {
@Id
public Long id;
public String name;
}
但是当我运行应用程序时,我得到了这个例外;
CreationException: Unable to create injector, see the following errors: 1)
Error injecting constructor, java.lang.IllegalStateException:
Bean class mods.SubModel is not enhanced?
显然,根项目中的模型得到了增强,但子项目中的模型却没有。我错过了什么?我怎么让这个工作?
答案 0 :(得分:0)
我有这个问题。我的一半模型都在我的子模块中。我把他们的ebean配置放在子模块的application.conf中。
您应该将以下行放在sub / conf / application.conf中:
ebean.sub = ["mods.*"]
然后在sub / build.sbt中添加以下行:
playEbeanModels in Compile := Seq("mods.*")