Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 播放2.6和Eben';s多DB源不工作_Playframework_Playframework 2.6 - Fatal编程技术网

Playframework 播放2.6和Eben';s多DB源不工作

Playframework 播放2.6和Eben';s多DB源不工作,playframework,playframework-2.6,Playframework,Playframework 2.6,我有2.6.5版本的Play和多模块(几个sbt子模块)配置。我设置了2个不同的数据源,但有一个错误: Caused by: javax.persistence.PersistenceException: models.common.defaultStorage.PromoBlock is NOT an Entity Bean registered with this server? at io.ebeaninternal.server.core.DefaultServer.create

我有2.6.5版本的Play和多模块(几个sbt子模块)配置。我设置了2个不同的数据源,但有一个错误:

Caused by: javax.persistence.PersistenceException: models.common.defaultStorage.PromoBlock is NOT an Entity Bean registered with this server?
    at io.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:1019)
    at io.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:975)
    at io.ebean.Finder.query(Finder.java:157)
    at models.common.defaultStorage.PromoBlock.findByProjectId(PromoBlock.java:84)
只有当我在
application.conf
中设置了2个数据源和相应的映射类设置时,才会发生这种情况

我的
build.sbt

lazy val common = (project in file("modules/common")).enablePlugins(PlayJava, PlayEbean)

lazy val admin = (project in file("modules/admin")).enablePlugins(PlayJava, PlayEbean).dependsOn(common)

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean).aggregate(common, admin).dependsOn(common, admin)
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.5")

...

addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.3")
我的ebean实体位于
公共
模块中。我在
root
项目中只有一个
application.conf
,还有两个数据源:

db {
    default.driver = org.postgresql.Driver
    default.url = "postgres://..."

    mssql.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
    mssql.url = "jdbc:sqlserver://..."
}

ebean.default = ["models.common.defaultStorage.*"]
ebean.mssql = ["models.common.mssqlStorage.*"]
我发现,如果我注释掉第二个
ebean.mssql
选项,一切都没问题。但对于两个不同的映射类列表,我得到了一个异常

我试着使用文档中的所有说明,但仍然没有成功

我的
插件.sbt

lazy val common = (project in file("modules/common")).enablePlugins(PlayJava, PlayEbean)

lazy val admin = (project in file("modules/admin")).enablePlugins(PlayJava, PlayEbean).dependsOn(common)

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean).aggregate(common, admin).dependsOn(common, admin)
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.5")

...

addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.3")

另外,我正在将项目从Play的2.4(以及之前的2.3)版本迁移到Play,在该版本中一切正常。

最新版本的Play ebean模块中存在一个bug,该模块将所有配置的数据源设置为默认值。拉取请求在9月6日打开,但仍未合并


事实上,我已经为埃宾·普罗杰特(ebean projet)这部剧开设了公关部

在我们的项目中,我们设立了一个变通办法。但是我们使用的是Java版本的Play2和Guice。我不知道如何在Scala中应用此解决方案。 在模块类中,我们将DefaultEbeanConfig.EbeanConfigParser绑定到我们自己的类

bind(DefaultEbeanConfig.EbeanConfigParser.class).to(CustomEbeanConfigParser.class);
此类的代码:

@Singleton
public class CustomEbeanConfigParser extends DefaultEbeanConfig.EbeanConfigParser implements Provider<EbeanConfig> {


    private final Config _config;

    @Inject
    public CustomEbeanConfigParser(Config config, Environment environment, DBApi dbApi) {
        super(config, environment, dbApi);
        this._config = config;
    }

    @Override
    public EbeanConfig parse() {
        DefaultEbeanConfig ebeanConfig = (DefaultEbeanConfig) super.parse();

        Map<String, ServerConfig> serverConfigMap = ebeanConfig.serverConfigs();
        for (Map.Entry<String, ServerConfig> entry : serverConfigMap.entrySet()) {
            entry.getValue().setDefaultServer(entry.getKey().equals(ebeanConfig.defaultServer()));
        }

        return ebeanConfig;
    }
}
@Singleton
公共类CustomEbeanConfigParser扩展DefaultEbeanConfig.EbeanConfigParser实现提供程序{
私有最终配置_Config;
@注入
公共CustomEbeanConfigParser(配置、环境、DBApi DBApi){
超级(配置、环境、dbApi);
这个。_config=config;
}
@凌驾
公共EbeanConfig解析(){
DefaultEbeanConfig ebeanConfig=(DefaultEbeanConfig)super.parse();
Map serverConfigMap=ebeanConfig.serverConfigs();
对于(Map.Entry:serverConfigMap.entrySet()){
entry.getValue().setDefaultServer(entry.getKey().equals(ebeanConfig.defaultServer());
}
返回ebeanConfig;
}
}
如您所见,我们使用提供的解析器的parse方法,在解析之后,我们修复了“defaultServer”属性