我是play-framework的新手(我希望与JSF / seam相比可以简化web开发)并且数据源出现问题(遗憾的是文档对这个问题没有帮助):
我需要多个数据源,因此数据源的名称与“default”不同。
这是application.conf:
db.monitoring.driver=org.postgresql.Driver
db.monitoring.url="jdbc:postgresql://localhost/skiline_monitoring"
db.monitoring.user=skiline
db.monitoring.password=skiline
ebean.monitoring="models.monitoring.*"
监控数据源的模型类位于包models.monitoring中。
模特级:
@Entity
public class SystemProperty extends Model {
@Column(length=100)
public String key;
@Column(length=1000)
public String value;
public static Finder<SystemPropertyKey, SystemProperty> find() {
return new Finder<SystemPropertyKey, SystemProperty>(SystemPropertyKey.class,
SystemProperty.class);
}
}
第一次调用SystemProperty.find()。all()会产生以下异常:
play.api.Application$$anon$1: Execution exception[[RuntimeException: DataSource user is null?]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.2]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:143) [play_2.10.jar:2.1.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:139) [play_2.10.jar:2.1.2]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.2]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.2]
java.lang.RuntimeException: DataSource user is null?
at com.avaje.ebeaninternal.server.lib.sql.DataSourcePool.<init>(DataSourcePool.java:184) ~[avaje-ebeanorm-server.jar:na]
at com.avaje.ebeaninternal.server.lib.sql.DataSourceManager.getDataSource(DataSourceManager.java:200) ~[avaje-ebeanorm-server.jar:na]
at com.avaje.ebeaninternal.server.lib.sql.DataSourceGlobalManager.getDataSource(DataSourceGlobalManager.java:46) ~[avaje-ebeanorm-server.jar:na]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.getDataSourceFromConfig(DefaultServerFactory.java:432) ~[avaje-ebeanorm-server.jar:na]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.setDataSource(DefaultServerFactory.java:393) ~[avaje-ebeanorm-server.jar:na]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:169) ~[avaje-ebeanorm-server.jar:na]
将文件ebean.properties添加到conf /目录没有帮助。那个conf / ebean.properties看起来像这样:
datasource.default=monitoring
datasource.monitoring.username=skiline
datasource.monitoring.password=skiline
datasource.monitoring.databaseUrl=jdbc:postgresql://localhost/skiline_monitoring
datasource.monitoring.databaseDriver=org.postgresql.Driver
datasource.monitoring.minConnections=1
datasource.monitoring.maxConnections=25
datasource.monitoring.heartbeatsql=select 1
datasource.monitoring.isolationlevel=read_committed
任何想法,我在这里缺少的东西(我使用的是最新的稳定版本2.1.2)?
答案 0 :(得分:4)
经过一些调试后我发现了问题:
如果数据源的名称与“default”不同,则必须在创建查找程序时指定server-name。
所以
public static Finder<SystemPropertyKey, SystemProperty> find() {
return new Finder<SystemPropertyKey, SystemProperty>(SystemPropertyKey.class,
SystemProperty.class);
}
必须更改为
public static Finder<SystemPropertyKey, SystemProperty> find() {
return new Finder<SystemPropertyKey, SystemProperty>("monitoring",
SystemPropertyKey.class, SystemProperty.class);
}