2013-07-30 35 views
2

我是新來的play-framework(與JSF/seam相比,我希望能夠簡化Web開發),並且有一個數據源的問題(不幸的是文檔不是真的有助於解決這個問題):不同於默認值的數據源導致DataSourcePool中的NPE

我需要多個數據源,因此數據源的名稱與「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()的第一個調用的所有()產生以下例外:

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)?

回答

4

一些調試後我發現這個問題:

如果數據源具有比「違約」,你必須創建一個取景器時指定服務器名稱不同的名稱。

所以

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); 
} 
+0

哇男人,我一直在敲打我的頭在這超過2小時。謝謝!!! –