我是 play-framework 的新手(与 JSF/seam 相比,我希望它可以简化 Web 开发)并且遇到了数据源问题(不幸的是,文档对这个问题并没有真正的帮助):
我将需要多个数据源,因此数据源的名称与“默认”不同。
这是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)?